2012-07-17 132 views
0

有誰知道如何使用php cURL從Google日曆中刪除活動? 我需要一個關於如何獲得eventid和如何刪除的例子。我做了一些調查,結果發現有一種方法可以用「CURLOPT_CUSTOMREQUEST」來做到這一點,但我找不到任何例子......如何使用cURL從Google日曆中刪除活動

+0

你試過什麼嗎?有沒有API? – 2012-07-17 01:49:37

+0

你在哪裏找到?我得到了[此](https://developers.google.com/google-apps/calendar/v3/reference/events)和[this](http://code.google.com/p/google-api-php -client/source/browse/trunk/examples/calendar/simple.php)。 – Jasonw 2012-07-17 02:02:22

+0

Google提供了一個PHP客戶端庫,用於與其各種服務(包括日曆)進行交互。 http://code.google.com/p/google-api-php-client/有一個簡單的例子,展示瞭如何使用客戶端庫來搗鼓日曆項目。 – Cheeso 2012-07-17 02:04:23

回答

0
$calendarId ="[email protected]"; 
    $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); 
+0

歡迎來到SO。請考慮向您的代碼添加解釋。 – 2017-02-06 10:07:09