0
我正嘗試使用Google的Calendar API創建(插入)新事件。我保持簡單並使用quickstart.php來測試。最初的quickstart.php代碼工作(獲取日曆事件),所以我知道我能夠連接。
然而,當我嘗試使用events.insert(),它給了我下面的錯誤:
PHP Notice: Undefined variable: service in /webroot/Website/TestWebsite/root/inc/Calendar/quickstart.php on line 43
很明顯,$服務沒有定義,但我不知道我錯過了什麼。
我使用Composer安裝了Google客戶端庫。
其他人有這個問題嗎?
下面是我的代碼:
<?php
require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Google Calendar API PHP Quickstart');
define('CREDENTIALS_PATH', '~/.credentials/calendar-php-
quickstart.json');
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/calendar-php-quickstart.json
define('SCOPES', implode(' ', array(
Google_Service_Calendar::CALENDAR)
));
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer
products.',
'start' => array(
'dateTime' => '2015-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2015-05-28T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => '[email protected]'),
array('email' => '[email protected]'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$calendarId = 'foo_calendar_ID';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
哦,男人,如此明顯!謝謝@noogui !. – Tim
@Tim我們都去過了:) – noogui