Google Calendar APIでの予定の操作〜スケジュール管理ソフトをS!アプリで作ってみよう(その20)

今回は、予定の操作方法について述べる。

予定の検索

予定の検索はいくつかの方法がある。


検索時のオプションのリファレンスは、こちら

予定の作成

新しい予定を作成する場合は、まず、以下の例のような予定のエントリを作成する。


<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:gd='http://schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>月例会議</title>
<content type='text'>進捗の報告と確認。</content>
<gd:transparency
value='http://schemas.google.com/g/2005#event.opaque'>
</gd:transparency>
<gd:eventStatus
value='http://schemas.google.com/g/2005#event.confirmed'>
</gd:eventStatus>
<gd:where valueString='第1会議室'></gd:where>
<gd:when startTime='2006-04-17T15:00:00.000Z'
endTime='2006-04-17T17:00:00.000Z'></gd:when>
</entry>

作成後に、まず、以下のようにデフォルトのURLへPOST要求を送し、contentに作成したエントリを送信する。(この時、content typeにapplication/atom+xmlを指定する。)


POST http://www.google.com/calendar/feeds/default/private/full

POST要求を送信すると、デフォルトのURLから、読み書き可能なプライベートのフィードのURLへリダイレクトされる。上記の要求に対して、GoogleカレンダーはHTTP 302のリダイレクトを返す。この時、リダイレクト先のURLは、「gsessionid」と言う新しいパラメータが付加されている。

リダイレクトを受け取ったら、そのURLに対して、同じPOST要求(同じ認証ヘッダ、同じcontentを含む)を送信する。(他にも、gsessionidも付け加える必要がある。)

2度目のPOST要求を送信すると、Googleカレンダーで予定が作成され、HTTP201 CREATEDのステータスコードと、送信したeventにいくつかの要素(例えばid)を加えたものが返ってくる。

予定の更新

予定の更新は、編集用のURLに対して、以下のような更新したい内容のentryと共にPUT要求を送信する。


<entry>
<id>http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID</id>
<published>2006-03-30T22:00:00.000Z</published>
<updated>2006-03-28T05:47:31.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>臨時役員会議</title>
<content type='text'>進捗の報告内容によっては、プロジェクトの中止もありうる。</content>
<link rel='alternate' type='text/html'
href='http://www.google.com/calendar/event?eid=aTJxcnNqbW9tcTJnaTE5cnMybmEwaW04bXMgbWFyY2guam9AZ21haWwuY29t'
title='alternate'></link>
<link rel='self' type='application/atom+xml'
href='http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID'></link>
<link rel='edit' type='application/atom+xml'
href='http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID/version' />
...
</entry>

編集用のURLは、上記の

<link rel='edit' type='application/atom+xml'
href='http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID/version' />
の部分のURLである。この部分は予定を作成、更新した時に返ってくるものに含まれている。

予定の削除

予定の削除は、編集用のURLに対して、DELETE要求を送信するだけである。

複数の予定のバッチ処理

複数の予定を一度に処理するための方法もあるのだが、その調査の結果は別の機会に記載する

次回から

次回からは、実際にGoogleカレンダーと連携するためのコードを実装していく。