ฉันมีปัญหาบางอย่างในการใช้ Google Calendar API โดยใช้ไลบรารีไคลเอนต์ PHP
ด้านล่างคือรหัสของฉัน:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
define("CLIENT_ID", "blah blah blah");
define("SERVICE_ACCOUNT_NAME", "blah blahblah");
define("KEY_FILE", "keykeykey.p12");
$client = new Google_Client();
$client->setApplicationName("Google Calendar Sample");
$client->setUseObjects(true);
session_start();
if (isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key)
);
$client->setClientId(CLIENT_ID);
$service = new Google_CalendarService($client);
///////////////////////////////////////////////////////////////////
try
{
$calendar = new Google_Calendar();
$calendar->setSummary('test');
$createdCalendar = $service->calendars->insert($calendar);
var_dump($createdCalendar);
}
catch(Google_ServiceException $e)
{
var_dump($e);
}
///////////////////////////////////////////////////////////////////
if ($client->getAccessToken())
{
$_SESSION['token'] = $client->getAccessToken();
}
?>
ดัมพ์ของ $createdCalendar เป็นดังนี้:
object(Google_Calendar)[15]
public 'kind' => string 'calendar#calendar' (length=17)
public 'description' => null
public 'summary' => string 'test' (length=3)
public 'etag' => string '"wT71Iy7ZAyY0SAhLu4jxO8w9qqM/zHZjSmLgdGM-FmXSbf2H0YONYb0"' (length=57)
public 'location' => null
public 'timeZone' => null
public 'id' => string '[email protected]' (length=52)
นี่แสดงว่าปฏิทินถูกสร้างขึ้นได้สำเร็จเนื่องจากมีการระบุ ID จาก Google อย่างไรก็ตาม ปฏิทินนี้ไม่ปรากฏในรายการปฏิทินเมื่อฉันเปิด Google ปฏิทินในเว็บเบราว์เซอร์
มีความคิดอะไรบ้าง?
BTW ฉันรู้แน่นอนว่าการตั้งค่า 2 Legged OAuth2 ของฉันใช้งานได้เพราะถ้าฉันแทนที่บล็อกของโค้ดระหว่าง ////////////// ด้วยสิ่งต่อไปนี้ มันจะทำงานได้ดี
$event = new Google_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2012-12-15T16:00:00.000-08:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-12-15T19:00:00.000-08:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('[email protected]');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
error.log
แล้วหรือยัง? - person feeela   schedule 13.12.2012google
,calendar
และapi
ไม่ได้หมายความว่าคุณกำลังพูดถึง Google Calendar API มีแท็กเดี่ยวแยกต่างหากสำหรับสิ่งนั้น - person Charles   schedule 13.12.2012