2016-09-20 16 views
1

カレンダーからGoogleカレンダーPHP APIを使用してイベントを取得しています。同じ設定を使用して別のカレンダーにアクセスする - GoogleカレンダーAPI PHP

すべてが最初のカレンダーで機能しますが、同じ設定を使用して別のカレンダー(同じGoogleアカウント)からイベントを受信しようとしています。

ログに次のエラーがあります:

PHPの致命的なエラー:/ WWW/WWW/apacheの/ドメインで:キャッチされない例外 'Google_Service_Exceptionは' メッセージ '(404)が見つかりませんでしたエラーが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 GET呼び出し' で。 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に同じデータを挿入すると、探しているイベントが正確に返されます。

答えて

1

Google Calendar APIの「Handling API Error」の「error 404」は、指定されたリソースが見つからないことを意味します。考えられる他の原因は、要求されたリソース(提供されたIDを持つ)が存在しなかったとき、またはユーザーがアクセスできないカレンダーにアクセスしたときです。

推奨アクションは、exponential backoffです。このSO question、この問題の原因別に基づき

service accountとプライベートのカレンダーにアクセスするとき、あなたはあなたがそれらのカレンダーを含むドメインを所有しているか、またはあなたがプライベートカレンダーを共有する必要がある場合の権限の委任を実行するのいずれか必要ですサービスアカウントの電子メールアドレス。

+1

それは、私はサービスの電子メールでカレンダーを共有するのを忘れてしまった!どうもありがとうございます! –

関連する問題