如何使用cURL从谷歌日历中删除事件


How to delete events from Google calendar using cURL

有人知道如何使用php-cURL从谷歌日历中删除事件吗?我需要一个关于如何获取事件ID和如何删除的示例。我做了一些研究,发现有一种方法可以用"CURLOPT_CUSTOMREQUEST"来实现,但我找不到任何例子。。。

   $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);