[英]Accessing Google Calendar using API v3
我正在尝试重写我以前没有使用 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 日历帐户并且所有日历都是共享的,所以应该没有问题,尽管我不明白为什么这是一个问题,因为我无论如何都使用经过身份验证的帐户。
任何人都可以提供建议?
非常感谢
你得到的错误
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
是因为对象是空的
代替
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}Undefined property
用这个摆脱错误。
if ($calendarList->getItems()) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}
还要调整以下
$this->client = new Google_Client();
需要是
$client = new Google_Client();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.