Google API日历 - 为特定日历创建活动

时间:2013-09-16 22:23:21

标签: php api google-calendar-api

我刚刚编写了相同的示例代码,在Google日历中创建了一个事件:

<?php

require_once __DIR__ . '/../../src/' . 'Google_Client.php';
require_once __DIR__ . '/../../src/' . 'contrib/Google_CalendarService.php';

 $client = new Google_Client();

$key = file_get_contents(__DIR__ . '/../../src/' . 'key.p12');
$client->setClientId('435615202702.apps.googleusercontent.com');

$client->setAssertionCredentials(
new Google_AssertionCredentials(
  'xxxxxxxx@developer.gserviceaccount.com',
  array('https://www.googleapis.com/auth/calendar'),
  $key
)
);

$service = new Google_CalendarService($client);



$event = new Google_Event();

$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2013-10-10T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2013-10-10T10:25:00.000-07:00');
$event->setEnd($end);

$event->setVisibility('public');
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('attt@somecompany.com');

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

var_dump($createdEvent);

?>

我得到了一个看似成功的回复:

array(17) {
  ["kind"]=>
  string(14) "calendar#event"
  ["etag"]=>
  string(52) ""HvdNzJLFsPN6WzLOxlO1URKnJIE/MTM3OTM2OTg0NTE3MzAwMA""
  ["id"]=>
  string(26) "44d949tpei3pf9ha0on4q62b58"
  ["status"]=>
  string(9) "confirmed"
  ["htmlLink"]=>
  string(134) "https://www.google.com/calendar        /event?eid=NDRkOTQ5dHBlaTNwZjloYTBvbjRxNjJiNTggNDM1NjE1MjAyNzAyQGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29t"
  ["created"]=>
  string(24) "2013-09-16T22:17:25.000Z"
  ["updated"]=>
  string(24) "2013-09-16T22:17:25.173Z"
  ["summary"]=>
  string(11) "Appointment"
  ["location"]=>
  string(9) "Somewhere"
  ["creator"]=>
  array(2) {
    ["email"]=>
    string(42) "xxxxx@developer.gserviceaccount.com"
    ["self"]=>
    bool(true)
  }
  ["organizer"]=>
  array(2) {
    ["email"]=>
    string(42) "xxxxx@developer.gserviceaccount.com"
    ["self"]=>
    bool(true)
  }
  ["start"]=>
  array(1) {
    ["dateTime"]=>
    string(20) "2013-10-10T17:00:00Z"
  }
  ["end"]=>
  array(1) {
    ["dateTime"]=>
    string(20) "2013-10-10T17:25:00Z"
  }
  ["visibility"]=>
  string(6) "public"
  ["iCalUID"]=>
  string(37) "44d949tpei3pf9ha0on4q62b58@google.com"
  ["sequence"]=>
  int(0)
  ["reminders"]=>
  array(1) {
    ["useDefault"]=>
    bool(true)
  }
}

问题是我在那个网址下得到“事件不存在”。如何指定我想要使用的确切日历以便将我的事件放在那里?

0 个答案:

没有答案