简体   繁体   中英

Google Calendar API v3 PHP new event

I'm trying to do add an event. I use client libraries. After passing oAuth I get

Fatal error: Call to a member function insert() on a non-object in zarzadzaj/kursy.php on line 17

My code is:

<?php
require_once '../zarzadzaj/src/Google_Client.php';
require_once '../zarzadzaj/src/contrib/Google_CalendarService.php';

$event = new Google_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);

$anEvent = $service->events->insert('primary', $event);

echo $anEvent->getId();
?>

What am i doing wrong?

I found the Solution...
You need to declare '$service' as an instance of the google calendar service first before you call the insert() method..This worked for me...I hope this works for you too..

$service = new Google_CalendarService($client);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM