0
我想使用谷歌日曆API和它的PHP客戶端庫,使一個PHP函數添加一個事件與變量我給它通過參數。谷歌API /日曆:無法找到使用谷歌API的方式
但似乎該文件已過時,我找不到一個很好的教程來幫助我。以下是我的時刻完成:
<?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
有人能幫助我嗎?