有谁知道如何使用 php cURL 从 Google 日历中删除事件?我需要一个关于如何获取 eventid 以及如何删除的示例。我做了一些研究,结果发现有一种方法可以用“CURLOPT_CUSTOMREQUEST”来做,但我找不到任何例子......
问问题
634 次
1 回答
0
$calendarId ="XXXXXXXXXXXXXX@group.calendar.google.com";
$eventId = 'XXXXXXXXXXXXXXXXXXXXX';
$APIKEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$tokenURL = 'https://accounts.google.com/o/oauth2/token';
$postData = array(
'client_secret'=>'XXXXXXXXXXXXXXXXX',
'grant_type'=>'refresh_token',
'refresh_token'=>'1/XXXXXXXXXXXXXXXXXXXXXXXX',
'client_id'=>'XXXXXXXXXXXXXXXXX.apps.googleusercontent.com'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tokenReturn = curl_exec($ch);
$token = json_decode($tokenReturn);
//var_dump($tokenReturn);
$accessToken = $token->access_token;
//$token = getAccessToken();
//echo $token; exit;
//var_dump($auth);
$request = 'https://www.googleapis.com/calendar/v3/calendars/' . $calendarId . '/events/'.$eventId.'?sendNotifications=true&key=' . $APIKEY;
$ch = curl_init($request);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '. $accessToken)
);
$response = curl_exec($ch);
$httpCode = curl_getinfo($response, CURLINFO_HTTP_CODE);
$result = json_decode($response);
于 2017-02-06T09:43:06.033 回答