【发布时间】:2015-02-14 02:20:42
【问题描述】:
我正在尝试使用 Google Calendar v3 API 重写以前没有编写过的旧应用程序。
我已经实现了 google-api-php-client,在我的开发者控制台中创建了一个 API 密钥,并完成了验证过程。我有一个accessToken,我将其保存在数据库中,当它过期时,我可以刷新该令牌。
但是,我无法对日历进行任何操作。
我正在关注已经存在的有限文档并具有以下内容:
$this->client = new Google_Client();
$this->client->setClientId( $this->settings['clientId'] );
$this->client->setClientSecret( $this->settings['clientSecret'] );
$this->client->setAccessToken( $this->settings['accessToken'] );
$service = new Google_Service_Calendar($this->client);
$calendarList = $service->calendarList->listCalendarList();
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
我回来的错误是:
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
我检查了我的 Google 日历帐户并且所有日历都是共享的,所以应该没有问题,尽管我不明白为什么这是个问题,因为我使用的是经过身份验证的帐户。
谁能提供建议?
非常感谢
【问题讨论】:
-
您是否尝试过在此处调试您的日历列表调用? developers.google.com/google-apps/calendar/v3/reference/… 只是为了确保您收到“$calendarList->getItems()”的回复
-
是的,当我使用“试试看”功能时,它会很好地返回日历。
-
你能发布 var_dump($calendarList->getItems()) 的输出吗?
-
是的,一个返回 NULL 的 var_dump
标签: php api google-calendar-api google-api-php-client