mad*_*ppo 5 php api google-calendar-api google-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;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
Run Code Online (Sandbox Code Playgroud)
我已经检查了我的Google日历帐户并且所有日历都是共享的,所以应该没有问题,虽然我不明白为什么这是一个问题,因为我正在使用经过身份验证的帐户.
有人能提供建议吗?
非常感谢
你得到的错误
Message: Undefined property: Google_Service_Calendar_CalendarList::$items
Run Code Online (Sandbox Code Playgroud)
是因为对象是空的
代替
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}Undefined property
Run Code Online (Sandbox Code Playgroud)
用这个来消除错误。
if ($calendarList->getItems()) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary();
}
Run Code Online (Sandbox Code Playgroud)
还要调整以下内容
$this->client = new Google_Client();
Run Code Online (Sandbox Code Playgroud)
需要是
$client = new Google_Client();
Run Code Online (Sandbox Code Playgroud)