无法使用php api删除Google日历中的事件

时间:2014-02-19 18:20:43

标签: php google-calendar-api google-oauth google-api-php-client

我正在使用PHP API到Google Calendar,我以前使用过Zend库,我正在升级到API V3,我下载了Git Hub客户端库v1.0。 我已经完成了oAuth 2,我将刷新令牌存储在数据库中。我可以将事件连接并写入Google日历,这主要归功于StackOverflow的贡献者。感谢

我的问题是我无法删除事件。我正在连接oAuth 2并检索事件ID但是

    $service->events->delete('primary', $event->getId());

这会生成致命错误:未捕获异常'Google_IO_Exception',并在C:\ wamp \ www \ new-roster-decoder \ src \ Google \ IO \ Stream.php中显示消息'HTTP错误:无法连接:'0''在第128行

我追求高低,无法找到解决方案。请帮忙谢谢

已编辑已解决 由于艾米丽的好建议,这个问题已经解决了 解决方案从GitHub下载了最新的API,因为GZIP的问题已经排序。 作为一个感兴趣的问题,我最初在congig.php中注释了GZIP并修复了它,但是我失去了性能优势,然后新的库对它进行了排序。 得到教训。 Stackoverflow用户非常友好地给他们的时间,并总是尝试最新的软件 结束编辑

   <?php
    /// This works

    session_start();

    set_include_path("src/" . PATH_SEPARATOR . get_include_path());
    require_once 'Google/Client.php';
    require_once 'Google/Service/Calendar.php';
    require_once 'account/dbc.php';



    $client_id = 'XXXXXXXXXX.apps.googleusercontent.com';
    $client_secret = 'XXXXXXXXXXX';
    $redirect_uri = 'http://localhost:80/new-roster-decoder/account/GoogleoAuth.php';


    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    $client->addScope("https://www.googleapis.com/auth/calendar");
    $client->setAccessType('offline');


    $users_rs_settings = mysqli_query($link,"select * from users WHERE id = 118");
    $users_array = mysqli_fetch_array($users_rs_settings);

    $refresh_token = $users_array['refresh_token'];  //2010-04-06
    $client->refreshToken($refresh_token);

    $service = new Google_Service_Calendar($client);

    $event = new Google_Service_Calendar_Event();  
    $event->setSummary('Positioning TX');
    $event->setLocation('BRS-LGW');

    $start = new Google_Service_Calendar_EventDateTime();
    $start->setDateTime('2014-02-19T14:00:00.000-00:00');
    $start->setTimeZone('Europe/London');
    $event->setStart($start);
    $end = new Google_Service_Calendar_EventDateTime();
    $end->setDateTime('2014-02-19T17:25:00.000-00:00');
    $end->setTimeZone('Europe/London');
    $event->setEnd($end);
     // insert ext properties
    $rdname = "RosterDecoderID";
    $rdvalue = 1;

    $extendedProperties = New Google_Service_Calendar_EventExtendedProperties();
    $extendedProperties->setPrivate(array($rdname=>$rdvalue));
    $event->setExtendedProperties($extendedProperties); 

    // end of insert ext properties

    $createdEvent = $service->events->insert('primary', $event);   
    echo $createdEvent->getId()."\n\n"; 

    $_SESSION['access_token'] = $client->getAccessToken();
    var_dump($_SESSION['access_token']);
    var_dump($event);

    $minCheck = date(DATE_ATOM, mktime(0, 0, 0, date("m"), date("d"), date("Y") ));
    $maxCheck = date(DATE_ATOM, mktime(0, 0, 0, date("m"), (date("d")+1), date("Y") ));

    $optParams = array( 'privateExtendedProperty' => 'RosterDecoderID=1','timeMin' => $minCheck, 'timeMax' => $maxCheck);
    $events = $service->events->listEvents('primary', $optParams);





   while(true) {
       foreach ($events->getItems() as $event) {
        $eventID = $event->getId();

    //////////////////////////////////////////////////////////
    //This bit throws an error
        $service->events->delete('primary', $event->getId());
    /////////////////////////////////////////////////////////
    // The error is
    // Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect: '0'' in C:\wamp\www\new-roster-decoder\src\Google\IO\Stream.php on line 128


         echo $event->getSummary();
         echo $event->getId()."\n\n"; 
      } 
    }

    ?>

2 个答案:

答案 0 :(得分:0)

我可以从谷歌日历中删除事件..

使用从开发者控制台获得的私钥文件。

更多信息请查看此链接

What is the Google API password for the OAuth PKCS p12 private key?

how-where-to-obtain-a-p12-key-file-from-the-google-developers-console

下面是代码,请检查

myapp-bar.log

答案 1 :(得分:0)

$service->events->delete('primary', $event->getId());

'primary' 必须是日历 ID

“myname@gmail.com”或“mhggf54gfh5@group.calendar.google.com”

这就是我的工作方式