请求谷歌日历api



我创建的web应用程序将与谷歌日历一起使用。我使用Guzzle进行http请求。我成功授权并获得代币。当我试图在某个日历中添加事件时,遇到了一些问题。

$url = 'https://www.googleapis.com/calendar/v3/calendars/'. $calendar_id .'/events';
$client = new GuzzleHttpClient();
$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

请解释一下怎么了?

非常感谢!

我想你是想做的

use GuzzleHttpClient;
$url = 'https://www.googleapis.com/calendar/v3/calendars/'. $calendar_id .'/events';
$client = new GuzzleClient($url);

相关内容

  • 没有找到相关文章

最新更新