我使用Google日曆PHP API從日曆獲取事件。使用相同設置訪問另一個日曆 - Google Calendar API PHP
一切工作與最初的日曆,但現在我試圖使用相同的設置從另一個日曆(相同的谷歌帳戶)接收事件。
有在日誌中以下錯誤:
PHP致命錯誤:未捕獲的異常 'Google_Service_Exception' 與消息 '錯誤調用GET https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID.calendar.google.com/events?maxResults=999&orderBy=startTime&singleEvents=true&timeZone=Europe%2FTallinn&timeMin=2016-09-19T00%3A01%3A00Z&timeMax=2018-07-17T00%3A00%3A00Z:(404)未找到' 是/ www /阿帕奇/域/萬維網。 domain.ee/htdocs/wp-content/themes/THEME/booking/vendor/google/apiclient/src/Google/Http/REST.php:79
而這裏的代碼(只有我chaged就是$calendarId
)
require_once 'vendor/autoload.php';
$client_email = '[email protected]';
$private_key = file_get_contents('name.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Calendar($client);
// Print the next 999 events on the user's calendar.
$calendarId = '[email protected]';
$optParams = array(
'maxResults' => 999,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeZone' => 'Europe/Tallinn',
'timeMin' => '2016-09-19T00:01:00Z',
'timeMax' => '2018-07-17T00:00:00Z',
);
$results = $service->events->listEvents($calendarId, $optParams);
將相同的數據插入到Google API Explorer中會返回我正在查找的事件。
就是這樣,我忘記與服務的電子郵件共享日曆!非常感謝! –