[英]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.