Google Calendar PHP API ไม่สามารถสร้างปฏิทินได้

ฉันมีปัญหาบางอย่างในการใช้ 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);

person user1772255    schedule 12.12.2012    source แหล่งที่มา
comment
นี่คือการใช้ V3 ของ API ปฏิทิน   -  person user1772255    schedule 13.12.2012
comment
ฉันไม่เข้าใจว่าคุณหมายความว่าอย่างไร. คุณได้ตรวจสอบ Apache error.log แล้วหรือยัง?   -  person feeela    schedule 13.12.2012
comment
หลังจากที่โค้ดส่วนนั้นทำงานแล้ว ปฏิทินใหม่ที่สร้างขึ้นไม่ควรแสดงภายใต้ 'ปฏิทินของฉัน' ในเว็บไซต์ Google ปฏิทินใช่หรือไม่   -  person user1772255    schedule 13.12.2012
comment
คุณได้นำเข้าข้อมูลดังกล่าวในบัญชี Google Calendars ของคุณหรือไม่   -  person feeela    schedule 13.12.2012
comment
ไม่แน่ใจว่าเกี่ยวข้องกับการนำเข้าปฏิทินหรือไม่...   -  person user1772255    schedule 13.12.2012
comment
โปรดทราบว่าแท็กจะอยู่เพียงลำพัง นั่นคือการรวม google, calendar และ api ไม่ได้หมายความว่าคุณกำลังพูดถึง Google Calendar API มีแท็กเดี่ยวแยกต่างหากสำหรับสิ่งนั้น   -  person Charles    schedule 13.12.2012
comment
แต่ฉันไม่เข้าใจด้วยซ้ำว่าปัญหาของคุณอยู่ที่รหัสของคุณหรือการใช้ Google Calendars   -  person feeela    schedule 13.12.2012
comment
ฉันไม่เคยทำสิ่งนี้มาก่อน (ดังนั้นจึงไม่ได้โพสต์เป็นคำตอบเว้นแต่จะได้ผล) แต่ฉันคิดว่าคุณต้องเพิ่มทรัพยากรปฏิทิน (ซึ่งคุณมี ID) ลงใน CalendarList ของผู้ใช้ (developers.google.com/google-apps/calendar/v3/reference/) นี่เป็นการตั้งค่าสิ่งต่างๆ เช่น สี การเตือนเริ่มต้น ฯลฯ และน่าจะอนุญาตให้ผู้ใช้รายนั้นมองเห็นได้   -  person Robbie    schedule 03.11.2016
comment
คุณได้ลองเข้าสู่ระบบและออกจากระบบบัญชี Google ของคุณแล้วหรือยัง?   -  person PauAI    schedule 09.11.2016


คำตอบ (1)


ฉันพบว่ารหัสที่คล้ายกันของฉันสร้างปฏิทินสำหรับผู้ใช้ Google API ([email protected]) แต่ไม่ใช่ฉัน ตรวจสอบ 'id' ของปฏิทินแรกที่มีอยู่แล้วคุณจะเห็น [email protected]

person user2300322    schedule 19.04.2013