2012-07-17 144 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