我尝试在日历中添加一个事件。我在谷歌控制台中创建了一个正确的应用程序,得到了ID,秘密等等。我甚至获得了已创建事件的ID,但此事件在日历仪表板中不可见。
session_start();
require_once dirname(__FILE__).'google-api-php-client/src/Google_Client.php';
require_once dirname(__FILE__).'google-api-php-client/src/contrib/Google_CalendarService.php';
ini_set('display_errors', 1);
define('CLIENT_ID','XXX');
define('SERVICE_ACCOUNT_NAME','XXX');
define('KEY_FILE',dirname(__FILE__).'API Project-XXX.p12');
$client = new Google_Client();
$client->setApplicationName("Kalendarz");
$client->setUseObjects(true); //IF USING SERVICE ACCOUNT (YES)
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,array('https://www.googleapis.com/auth/calendar'),$key));
$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);
$calList = $cal->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
if (isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
// Creates a test event
$event = new Google_Event();
$event->setSummary('Appointment2');
$event->setLocation('Somewhere2');
$start = new Google_EventDateTime();
$start->setDateTime('2014-10-11T10:00:00.000-01:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2014-10-11T10:25:00.000-01:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
//$attendee1->setEmail('XXX');
//$attendees = array($attendee1);
//$event->attendees = $attendee1;
//echo "<pre>";
//var_dump($cal);
$createdEvent = $cal->events->insert('primary', $event);
echo $createdEvent->getId();
/*
$event = new Google_Event();
$event = $service->events->get("XXX", $evID);
echo $event->getSummary();
*/
结果是:
Google_CalendarList Object
(
[etag] => "1412846388446000"
[__itemsType:protected] => Google_CalendarListEntry
[__itemsDataType:protected] => array
[items] => Array
(
)
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => 00001412846388446000
)
arkd3j1j8ilgi71p6pdp242gp0
答案 0 :(得分:0)
我认为您的活动已成功创建,其活动ID为arkd3j1j8ilgi71p6pdp242gp0;)