2012-04-10 17 views
0

API Googleを使用してアプリケーションを開発しています。この過程で我々はいくつかの困難に直面した。Googleカレンダーにイベントを追加する

このページにあるphp-sdkを使用しました。「code.google.com/p/google-api-php-client/」Googleカレンダーサービスを使用しました。 Googleでは、「developers.google.com/google-apps/calendar/v3/reference/」セクションのカレンダーとイベントのドキュメントに続いています。

ソースデータ:ここにあるGoogleカレンダーサービスにアクセスできます。「code.google.com/apis/console/」 - 必要な権限が必要です(「developers.google.com/google- apps/calendar/v3/reference/events/insert) "

タスク:カレンダーに予定を追加する。 処置:我々はhttps://www.googleapis.com/calendar/v3/calendars/ {calendarId} /イベントにポストリクエストを送信calendarIdが= {calendarId} & ALT = jsonを&キー= {APIキー}

リクエストボディ:?

{ 

"\u0000*\u0000__creatorType":"EventCreator", 

"\u0000*\u0000__creatorDataType":"", 

"\u0000*\u0000__organizerType":"EventOrganizer", 

"\u0000*\u0000__organizerDataType":"", 

"\u0000*\u0000__attendeesType":"EventAttendee", 

"\u0000*\u0000__attendeesDataType":"array", 

"\u0000*\u0000__startType":"EventDateTime", 

"\u0000*\u0000__startDataType":"", 

"start":{ 

"date":"", 

"timeZone":"Europe\/Moscow", 

"dateTime":"2012-0408T12:00:00+04:00" 

}, 

"location":"sdasdwqwqesaddsa", 

"\u0000*\u0000__originalStartTimeType":"EventDateTime", 

"\u0000*\u0000__originalStartTimeDataType":"", 

"\u0000*\u0000__gadgetType":"EventGadget", 

"\u0000*\u0000__gadgetDataType":"", 

"description":"sadasdzxczxcasdsaweqqwasd", 

"\u0000*\u0000__extendedPropertiesType":"EventExtendedProperties", 

"\u0000*\u0000__extendedPropertiesDataType":"", 

"\u0000*\u0000__endType":"EventDateTime", 

"\u0000*\u0000__endDataType":"", 

"end":{ 

"date":"", 

"timeZone":"Europe\/Moscow", 

"dateTime":"2012-04-08T19:00:00+04:00" 

}, 

"\u0000*\u0000__remindersType":"EventReminders", 

"\u0000*\u0000__remindersDataType":"", 

"summary":"wqeqwesadasewqe" 

} 

注:形成するためにイベントの目的我々は(APIから(この例ではここでdevelopers.google.com/google-apps/calendar/v3/reference/events/insert部分例と同じ)コード

Result: API returns an error with code 400 (Bad Request) 

回答を使用ヘッダー付き)

HTTP/1.1 400 Bad Request Content-Type: application/json; charset=UTF-8 Date: Fri, 06 Apr 2012 05:53:55 GMT Expires: Fri, 06 Apr 2012 05:53:55 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked 

{ "error": { 

"errors": [ 

{ "domain": "global", 

"reason": "badRequest", 

"message": "Bad Request" } 

], 

"code": 400, 

"message": "Bad Request" 

} 

} 

答えて

0

http://developers.google.com/google-apps/calendar/v3/reference上の)あなたが言及する文書は、GoogleカレンダーのAPIへのRESTインターフェイスを説明します。しかし、PHPクライアントライブラリは動作が異なり、残念ながらほとんど文書化されていません。

Google PHP APIクライアント(https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/calendar/simple.php)に付属のサンプルを使用しました。 GoogleのAPIコンソールでoAuthクライアントID、シークレットなどを生成する必要があります(この動作の仕組みはAPIクライアントのドキュメントに記載されています)。

カレンダーPHPのAPIについての他のすべてのドキュメントはGoogle_CalendarServiceクラスのコメントで発見される(私の知る限り)である:

https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_CalendarService.php

次のコードを使用してGoogleカレンダーに新しいイベントを追加することができます

$event = new Google_Event(); 

// Event title and location 
$event->setSummary('Event title'); 
$event->setLocation('Some location'); 

// Start and end time of the event 
$start = new Google_EventDateTime(); 
$start->setDateTime('2013-08-08T14:00:00+02:00'); 
$event->setStart($start); 

$stop = new Google_EventDateTime(); 
$stop->setDateTime('2013-08-08T16:00:00+02:00'); 
$event->setEnd($stop); 

// Insert event in calendar. 
// 'primary' may be replaced with a full @group.calendar.google.com calendar ID. 
$createdEvent = $cal->events->insert('primary', $event); 
関連する問題