Php $service未在Google日历API中定义
我正在尝试使用谷歌的日历API创建(插入)一个新事件。我保持它的简单性,并使用quickstart.php进行测试。最初的quickstart.php代码有效(获取日历事件),因此我知道我能够连接 但是,当我尝试使用时,会出现以下错误:Php $service未在Google日历API中定义,php,calendar,google-calendar-api,Php,Calendar,Google Calendar Api,我正在尝试使用谷歌的日历API创建(插入)一个新事件。我保持它的简单性,并使用quickstart.php进行测试。最初的quickstart.php代码有效(获取日历事件),因此我知道我能够连接 但是,当我尝试使用时,会出现以下错误: PHP Notice: Undefined variable: service in /webroot/Website/TestWebsite/root/inc/Calendar/quickstart.php on line 43 很明显,$service并
PHP Notice: Undefined variable: service in /webroot/Website/TestWebsite/root/inc/Calendar/quickstart.php on line 43
很明显,$service并没有定义,但我不确定我遗漏了什么
我使用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' => 'lpage@example.com'),
array('email' => 'sbrin@example.com'),
),
'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);
使用PHP快速启动时,$service
变量正在工作,因为它是在此行中定义的
$service = new Google_Service_Calendar($client);
现在,您修改了代码,它开始发出错误。看着你的代码,你似乎已经删除了它。现在您知道是什么导致了它:)当您使用PHP快速启动时,$service
变量正在工作,因为它是在这一行中定义的
$service = new Google_Service_Calendar($client);
现在,您修改了代码,它开始发出错误。看着你的代码,你似乎已经删除了它。现在你知道是什么原因了:)@Tim我们都去过:)@Tim我们都去过:)