2014-10-16 3 views
0

Я пытаюсь использовать Google Calendar api и его клиентскую библиотеку php для создания функции php, которая добавляет событие с переменными, которые я передаю через параметры.Google API/Календарь: не удается найти способ использования google 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 

Может кто-нибудь мне помочь, пожалуйста?

ответ

Смежные вопросы