请求谷歌日历api

时间:2015-04-01 22:11:32

标签: google-api google-calendar-api guzzle

我创建了可与Google日历一起使用的网络应用程序。 我使用Guzzle来获取http请求。 我成功授权并获得了令牌。 当我试图在某个日历中添加事件时,我遇到了一些麻烦。

$url = 'https://www.googleapis.com/calendar/v3/calendars/'. $calendar_id .'/events';
$client = new Guzzle\Http\Client();

$data = json_encode(array(
  "end" => array("date" => "2015-04-02"),
  "start" => array("date" => "2015-04-01"),
  "summary" => "test3"
));

$request = $client->post($url, [], $data);
$request->setHeader('Authorization', $token_type . ' ' . $token);
$response = $request->send();
echo $response->getBody();

回复是

Client error response [status code] 400 [reason phrase] Bad Request [url] https://www.googleapis.com/calendar/v3/calendars/some_calendar/events

请解释我有什么问题?

非常感谢!

1 个答案:

答案 0 :(得分:0)

我认为你打算这样做

use Guzzle\Http\Client;

$url = 'https://www.googleapis.com/calendar/v3/calendars/'. $calendar_id .'/events';

$client = new GuzzleClient($url);