利用手順
Google のアカウントと Google Calendar サービスを利用できるようにしておきます。
Google にログインします
https://www.google.com/accounts/ClientLogin?Email=登録したメールアドレス&Passwd=パスワード&source=アプリケーション名&service=cl
というリクエストを発行します。source に指定するアプリケーション名は company-application-version にします。service は cl で固定です。これは calendar を示しているようです。
サーバーから
SID=XXX... LSID=XXX... Auth=XXX...
と返信が返ってきます。ここでは Auth だけが必要になるので値を保持します。
以降、サーバーとやりとりする際にはヘッダに Auth を付加します。
Authorization: GoogleLogin auth=XXX...
gsessionid を取得する
サーバーに何らかのリクエストを発行するとまず HTTP 302 が返ってきます。
レスポンスヘッダの Location を見ると、
Location: http://www.google.com/calendar/feeds/default?gsessionid=XXX...
のようになっています。どのようなリクエストでもこのように返ってくるので、リダイレクトするようにラップしても良いのですが、クエリの gsessionid を保持してリクエスト URL にクエリとして追加すると余計な通信が発生しません。
また、gsessionid が無効になると再度 302 が返ってきます。
カレンダーのリストを取得する
http://www.google.com/calendar/feeds/登録したメールアドレス
というリクエストをサーバーに発行します。
サーバーから返信されます。
- サービスのレスポンス
<?xml version='1.0' encoding='UTF-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/登録したメールアドレス</id> <updated>2006-08-09T21:18:25.173Z</updated> <title type='text'>設定したサービス名's Calendar List</title> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス'></link> <link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス'></link> <link rel='next' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス?start-index=7&max-results=6'></link> <author> <name>設定したサービス名</name> <email>登録したメールアドレス</email> </author> <generator version='1.0' uri='http://www.google.com/calendar'>Google Calendar</generator> <entry> <id>http://www.google.com/calendar/feeds/登録したメールアドレス/登録したメールアドレス</id> <published>2006-08-09T21:18:25.177Z</published> <updated>2006-08-09T14:31:36.000Z</updated> <title type='text'>プライマリカレンダー名</title> <link rel='alternate' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス/private/full'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/登録したメールアドレス/登録したメールアドレス'></link> <author> <name>名前</name> <email>メールアドレス</email> </author> <gCal:color xmlns:gCal='http://schemas.google.com/gCal/2005' value='#2952A3'></gCal:color> <gCal:hidden xmlns:gCal='http://schemas.google.com/gCal/2005' value='false'></gCal:hidden> <gCal:accesslevel xmlns:gCal='http://schemas.google.com/gCal/2005' value='owner'></gCal:accesslevel> <gCal:selected xmlns:gCal='http://schemas.google.com/gCal/2005' value='true'></gCal:selected> <gCal:timezone xmlns:gCal='http://schemas.google.com/gCal/2005' value='Asia/Tokyo'></gCal:timezone> <gd:where valueString='場所'></gd:where> </entry> ... </feed>
カレンダーリストとサービスの情報を取得するには /feed/id/text() を使用します。
カレンダーは登録したメールアドレスを ID としたプライマリカレンダーと、別に作成されたカレンダー、他人が公開しているカレンダーがすべて列挙されます。プライマリカレンダーは必ず最初に列挙されるようですが、その後の順序は安定しないようです。
カレンダーの情報を個別に取得したいときは、/feed/entry/id/text() を使用します。
カレンダーに登録されたイベントのリストを取得する
サービスのレスポンスの XML において、/feed/entry/link[@rel='alternative']/@href がそれぞれのカレンダーのイベントのリストを取得するための URL です。リクエストをサーバーに発行すると、以下のように返信されます。
- カレンダーのレスポンス
<?xml version='1.0' encoding='UTF-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/カレンダーのID/private/full</id> <updated>2006-08-09T09:51:55.000Z</updated> <title type='text'>タイトル</title> <subtitle type='text'>サブタイトル</subtitle> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full'></link> <link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full?max-results=25'></link> <link rel='next' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full?start-index=26&max-results=25'></link> <author> <name>発行者</name> <email>メールアドレス</email> </author> <generator version='1.0' uri='http://www.google.com/calendar'>Google Calendar</generator> <openSearch:itemsPerPage>25</openSearch:itemsPerPage> <gd:where valueString='場所'></gd:where> <gCal:timezone xmlns:gCal='http://schemas.google.com/gCal/2005' value='Asia/Tokyo'></gCal:timezone> <entry> <id>http://www.google.com/calendar/feeds/カレンダーのID/private/full/イベントのID</id> <published>2006-08-09T08:01:28.000Z</published> <updated>2006-08-09T08:01:28.000Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category> <category scheme='http://schemas.google.com/g/2005' term='http://schemas.google.com/g/2005#event'></category> <title type='text'>Python</title> <content type='text'></content> <link rel='alternate' type='text/html' href='http://www.google.com/calendar/event?eid=イベントのID1' title='alternate'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full/イベントのID2'></link> <link rel='edit' type='application/atom+xml' href='http://www.google.com/calendar/feeds/カレンダーのID/private/full/イベントのID2/バージョンのID'></link> <author> <name>発行者</name> </author> <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'></gd:eventStatus> <gd:visibility value='http://schemas.google.com/g/2005#event.default'></gd:visibility> <gd:comments> <gd:feedLink href='http://www.google.com/calendar/feeds/カレンダーのID/private/full/イベントのID/comments'></gd:feedLink> </gd:comments> <gd:transparency value='http://schemas.google.com/g/2005#event.opaque'></gd:transparency> <gd:where valueString=''></gd:where> <gd:when startTime='2006-08-08' endTime='2006-08-09'> <gd:reminder minutes='10'></gd:reminder> </gd:when> </entry> ... </feed>
イベントを追加するには、/feed/id/text() に /feed/entry 以下の内容の XML を POST します。XML の内容については http://code.google.com/apis/gdata/calendar.html#add_event を参照して下さい。成功すると HTTP 201 が返ります。
イベントを確認するには、/feed/entry/id/text() に GET を発行します。成功すると HTTP 200 が返ります。
イベントを変更するには、/feed/entry/link[@rel='edit']/@href に /feed/entry 以下の内容の XML を PUSH します。成功すると HTTP 200 が返ります。
イベントを削除するには、/feed/entry/link[@rel='edit']/@href に DELETE を発行します。成功すると HTTP 200 が返ります。