我知道有很多相关问题,我现在已经尝试了2-3天而没有任何成功。
我的网页上有一个日历,用户可以在其中选择日期和时间,然后点击一个按钮,该条目将在我的(所有者)Google日历中创建,无需任何身份验证。我已将Google日历设为公开。这是我的代码:
require_once __DIR__ . '/google-api-php-client-2.2.1/vendor/autoload.php';
$DEVELOPER_KEY = 'some-key-here';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$calendar = new 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' => '2018-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2018-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 = 'someid@gmail.com';
$event = $calendar->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
当我运行时,我收到错误
Fatal error: Call to a member function insert() on null
我在哪里弄错了或者我错过了什么?请帮忙。
答案 0 :(得分:0)
我相信$calendar = new Google_Service_Calendar_Calendar();
应该是$calendar = new Google_Service_Calendar();