Невозможно вставить событие в определенный календарь с помощью google-api-php-client

Пытаюсь вставить событие с google-api-php-client в определенный календарь.
Если вместо «Идентификатор календаря» установить «основной», он будет работать, но я не вижу события в основном календаре.

Если я пытаюсь указать идентификатор календаря, например [email protected], у меня возникает следующая ошибка:

Неустранимая ошибка: необработанное исключение «Google_Service_Exception» с сообщением «Ошибка вызова POST https://www.googleapis.com/calendar/v3/calendars/xxxxx8egm4tng6rlj8usmavdu8%40google.com/events: (404) Not Found ‘в /var/www/clients/client1/web347/web/google-api-php/src/Google/Http/REST.php:111 трассировке стека: # 0 / var / www / clients / client1 / web347 / web / google-api-php / src / Google / Http / REST.php (63): Google_Http_REST ::

вот мой код Аутентификация работает

    $cal_id = 'primary';  // IT WORKS, BUT I DON'T SEE THE EVENT IN MAIN CALENDAR
$cal_id = '[email protected]'; // IT CAUSES THE ERROR

//Set the Event data
$event = new Google_Service_Calendar_Event();
$event->setSummary($title);
$event->setDescription($desc);

$ev_date = '2015-01-05T08:00:00+01:00';

$start = new Google_Service_Calendar_EventDateTime();
$start->setTimeZone('Europe/London');
$start->setDateTime('2015-01-01T19:15:00');
$event->setStart($start);

$end = new Google_Service_Calendar_EventDateTime();
$end->setTimeZone('Europe/London');
$end->setDateTime('2015-01-05T20:15:00');
$event->setEnd($end);

$createdEvent = $calendarService->events->insert( $cal_id, $event);
$event = $calendarService->events->get($cal_id, $createdEvent->getId());
//
if ($event != null) {
echo "Inserted:";
echo "EventID=".$event->getId();
echo "Summary=".$event->getSummary();
echo "Status=".$event->getStatus();
}

$ madeEvent вернет этот код с помощью «основного» календаря

Google_Service_Calendar_Event Object
(
[collection_key:protected] => recurrence
[internal_gapi_mappings:protected] => Array
(
)

[anyoneCanAddSelf] =>
[attendeesType:protected] => Google_Service_Calendar_EventAttendee
[attendeesDataType:protected] => array
[attendeesOmitted] =>
[colorId] =>
[created] => 2015-01-05T11:21:03.000Z
[creatorType:protected] => Google_Service_Calendar_EventCreator
[creatorDataType:protected] =>
[description] => test
[endType:protected] => Google_Service_Calendar_EventDateTime
[endDataType:protected] =>
[endTimeUnspecified] =>
[etag] => "2840913726324000"[extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties
[extendedPropertiesDataType:protected] =>
[gadgetType:protected] => Google_Service_Calendar_EventGadget
[gadgetDataType:protected] =>
[guestsCanInviteOthers] =>
[guestsCanModify] =>
[guestsCanSeeOtherGuests] =>
[hangoutLink] =>
[htmlLink] => https://www.google.com/calendar/event?eid=M2p2ZXY1cmZpY2Y3dTk5MjQ0ZmNsYW9xNTggMTAwNjUzNTQ3ODk1My1laTI5a2M4cGQxZHE3cDUycGhtdmRlMWs3dXZkZjIzb0BkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbQ
[iCalUID] => [email protected]
[id] => 3jvev5rficf7u99244fclaoq58
[kind] => calendar#event
[location] =>
[locked] =>
[organizerType:protected] => Google_Service_Calendar_EventOrganizer
[organizerDataType:protected] =>
[originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime
[originalStartTimeDataType:protected] =>
[privateCopy] =>
[recurrence] =>
[recurringEventId] =>
[remindersType:protected] => Google_Service_Calendar_EventReminders
[remindersDataType:protected] =>
[sequence] => 0
[sourceType:protected] => Google_Service_Calendar_EventSource
[sourceDataType:protected] =>
[startType:protected] => Google_Service_Calendar_EventDateTime
[startDataType:protected] =>
[status] => confirmed
[summary] => test
[transparency] =>
[updated] => 2015-01-05T11:21:03.162Z
[visibility] =>
[modelData:protected] => Array
(
[creator] => Array
(
[email] => 1006535478953-ei29kc8pd1dq7p52phmvde1k7uvdf23o@developer.gserviceaccount.com
[self] => 1
)

[organizer] => Array
(
[email] => 1006535478953-ei29kc8pd1dq7p52phmvde1k7uvdf23o@developer.gserviceaccount.com
[self] => 1
)

[start] => Array
(
[dateTime] => 2015-01-01T19:15:00Z
[timeZone] => Europe/London
)

[end] => Array
(
[dateTime] => 2015-01-05T20:15:00Z
[timeZone] => Europe/London
)

[reminders] => Array
(
[useDefault] => 1
)

)

[processed:protected] => Array
(
)

)

-1

Решение

сначала вы получите список календарей, используя

print_r($calendarList = $calendarService->calendarList->listCalendarList());

Затем получите идентификатор вашего конкретного календаря, и вы можете установить

$createdEvent = $calendarService->events->insert('NEW_ID', $event);
2

Другие решения

    <?php
error_reporting(1);
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';

$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('XXXXXXXXXX');
$client->setClientSecret('XXXXXXXXX');
$client->setRedirectUri('XXXXXXXXXX');

$client->setScopes(array('https://www.googleapis.com/auth/calendar')); //Calender Scope

$cal=new Google_CalendarService($client);

$authUrl = $client->createAuthUrl();

$authCode = trim(fgets(STDIN));

if(!file_exists("token.json") || filesize("token.json")==0)
{
// Save token for future use

$accessToken = $client->authenticate($authCode);
$client->setAccessToken($accessToken);
if ($client->getAccessToken()) {
$token = $client->getAccessToken();
$authObj = json_decode($token);
$refreshToken = $authObj->refresh_token;
}
file_put_contents("token.json",$refreshToken);
}
else
{
$accessToken = file_get_contents("token.json");
//echo "hi:";
$client->refreshToken($accessToken);
$client->getAccessToken();
}
//Create Calender Event
$event = new Google_Event();
$event->setSummary('Appointment');
$event->setLocation('Rajkot');
//$event->sendNotifications('TRUE');
$start = new Google_EventDateTime();
$start->setDateTime('2014-12-24T11:20:00.000+05:30');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2014-12-24T11:30:00.000+05:30');
$event->setEnd($end);
$event->setHangoutLink(null);

$reminderI = new Google_EventReminder();
$reminderI->setMethod('popup');
$reminderI->setMinutes('5');

$reminderII = new Google_EventReminder();
$reminderII->setMethod('email');
$reminderII->setMinutes('10');

$reminder = new Google_EventReminders();
$reminder->setUseDefault('false');
$reminder->setOverrides(array($reminderI,$reminderII));
$event->setReminders($reminder);

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

print_r($createdEvent);
?>
0

По вопросам рекламы [email protected]