我尝试在特定日历中插入带有google-api-php-client的活动。 如果我设置' primary'相反,日历ID,它正在运作,但我在主日历中看不到该事件。
我尝试指定日历ID,例如co-xxxxx.ch_lhr1ojekr990m475kv6nilueqs@group.calendar.google.com,我有以下错误:
致命错误:未捕获的异常' 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 = 'xxxxx38egm4tng6rlj8usmavdu8@google.com'; // 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();
}
$ createdEvent使用' primary'返回此代码日历
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] => 3jvev5rficf7u99244fclaoq58@google.com
[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
(
)
)
答案 0 :(得分:2)
首先使用
获取日历列表print_r($calendarList = $calendarService->calendarList->listCalendarList());
然后获取您特定日历的ID,您可以通过
进行设置$createdEvent = $calendarService->events->insert('NEW_ID', $event);
答案 1 :(得分:0)
<?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);
?>