Google API /日历:无法找到使用google api的方法

时间:2014-10-16 12:00:00

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

我试图使用Google日历api及其php客户端库来创建一个php函数,用我通过参数给出的变量添加一个事件。

但似乎文档已经过时,我找不到一个好的教程来帮助我。以下是我目前所做的事情:

<?php
require_once 'google-api-php-client/autoload.php';

session_start();
//require_once 'google-api-php-client/src/Google/Client.php';
//require_once 'google-api-php-client/src/Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("test");
$client->setClientId("xxxx.apps.googleusercontent.com");
$client->setClientSecret("xxxx");
$client->setRedirectUri("http://localhost/");
$client->setDeveloperKey("xxxx");
$service = new Google_Service_Calendar($client);

$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-10-16T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-10-16T10:25:00.000-07:00');
$event->setEnd($end);


/*$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;*/

$createdEvent = $service->events->insert('primary', $event);

echo $createdEvent->getId();
?>

我的浏览器告诉我:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key=xxxx: (401) Login Required' in C:\wamp\www\cnsi\google-api-php-client\src\Google\Http\REST.php on line 76
有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我建议您使用Zend Framework库。

结帐http://framework.zend.com/manual/1.12/en/zend.gdata.calendar.html