2013-10-21 190 views
0

我正在尝试添加事件。我使用客户端库。 路过的OAuth后,我得到Google Calendar API v3 PHP新事件

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

我的代码是:

<?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(); 
?> 

我到底做错了什么?

+0

http://stackoverflow.com/questions/13840594/how-to-create-an-event-on-google-calendar-using-php阅读本.. – MODEV

+0

@MODEV我不相信这个问题是相关的。谷歌自那时以来已经改变了他们的API,并且该主题中的解决方案虽然可以作为寻找解决方案的起点,但现在可能已经过时。在开始意识到这是旧代码之前,我花了半天的时间搞砸这些废话......当涉及到这一点时,Goog的文档仍然是一团糟。 – Cyprus106

回答

0

我找到了解决方案...
在调用insert()方法之前,您需要先声明'$ service'作为google日历服务的一个实例..这对我有效......我希望这为你工作太..

$service = new Google_CalendarService($client); 
+0

我得到:未找到类'Google_CalendarService':( – Andri