【发布时间】:2014-03-14 19:24:43
【问题描述】:
我正在尝试直接从 php 脚本将事件添加到 Google 日历,但出现此错误:
致命错误:在非对象上调用成员函数 insert()...
<?php
set_include_path("scripts/google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
$path = $_SERVER['DOCUMENT_ROOT'];
$google_client = $path . '/xxxx/scripts/google-api-php-client/src/Google_Client.php';
include ($google_client);
require_once $path . '/xxxx/scripts/google-api-php-client/src/contrib/Google_CalendarService.php';
$event = new Google_Event();
$event->setSummary('Pi Day');
$event->setLocation('Math Classroom');
$start = new Google_EventDateTime();
$start->setDateTime('2013-03-14T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2013-03-14T10:25:00.000-05:00');
$event->setEnd($end);
// error is on this next line
$createdEvent = $cal->events->insert('some_calendar@gmail.com', $event);
echo $createdEvent->id;
?>
我在许多我看过的示例中看到了一些使用类似于此的代码:
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Event Creator");
$client->setClientId('MY CLIENT ID ADDRESS IS HERE');
$client->setClientSecret('MY CLIENT SECRET KEY IS HERE');
$client->setRedirectUri('http://localhost/phpt/caladd.php');
$client->setDeveloperKey('MY API KEY IS HERE');
$cal = new Google_CalendarService($client);
但这在我看来好像有一些应用程序正在被引用并且是生成日历事件的原因。就我而言,理想情况下,我只希望我的 php 脚本创建日历条目。不涉及其他“应用程序”。
我是否需要拥有 Google_Client 才能将简单条目添加到 Google 日历?对我来说这似乎太过分了,但也许这是唯一的方法。
我是否忽略了这个过程中的一个步骤?或者我写的代码中是否存在错误。任何帮助表示赞赏,包括示例链接。谢谢。
【问题讨论】: