我试图执行使用到谷歌日历API的卷曲请求,上面写着:插入事件,谷歌日历使用PHP
POST https://www.googleapis.com/calendar/v3/calendars/{name_of_my_calendar}/events?sendNotifications=true&pp=1&key={YOUR_API_KEY}
Content-Type: application/json
Authorization: OAuth 1/SuypHO0rNsURWvMXQ559Mfm9Vbd4zWvVQ8UIR76nlJ0
X-JavaScript-User-Agent: Google APIs Explorer
{
"start": {
"dateTime": "2012-06-03T10:00:00.000-07:00"
},
"end": {
"dateTime": "2012-06-03T10:20:00.000-07:00"
},
"summary": "my_summary",
"description": "my_description"
}
我应该怎么做,在PHP?我想知道我应该发送什么参数以及我应该使用哪些常量。目前,我正在做的:
$url = "https://www.googleapis.com/calendar/v3/calendars/".urlencode('{name_of_my_calendar}')."/events?sendNotifications=true&pp=1&key={my_api_key}";
$post_data = array(
"start" => array("dateTime" => "2012-06-01T10:00:00.000-07:00"),
"end" => array("dateTime" => "2012-06-01T10:40:00.000-07:00"),
"summary" => "my_summary",
"description" => "my_description"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// adding the post variables to the request
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
但响应:
{
error: {
errors: [
{
domain: "global",
reason: "required",
message: "Login Required",
locationType: "header",
location: "Authorization"
}
],
code: 401,
message: "Login Required"
}
}
我应该如何格式化我的参数?
您是否阅读了https://developers.google.com/google-apps/calendar/auth? – Daan 2012-04-19 08:44:17
是的,我的代码只用于解析来自同一日历的事件的示例。 – Gustav 2012-04-19 08:46:12
嗯。不知道,我以前从未使用过此API。你可能想试试官方的PHP API包:http://code.google.com/p/google-api-php-client/希望这会有所帮助! – Daan 2012-04-19 17:45:52