Google Calendar API(2)
Google Calendar API(1)
この前は、単に公開カレンダーのフィードを取得するだけだったので、今回はもう少し条件を絞り込んでフィードを取得したいと思います。GoogleのドキュメントではこのページにカレンダーAPIのパラメータについての情報があります。
- API Reference Guide Google Calendar APIs and Tools(Google Calendar API固有)
- Protocol Reference Google Data APIs(Google Data API共通)
出力順
orderby で指定します。
- lastmodified:更新日時(デフォルト)
- starttime:開始日時
昇順/降順の指定はsortorder=ascending(a),descending(d)を追加します。
範囲
start-min、start-maxにてRFC3339形式で日時を指定します。
start-min=2009-05-01T00:00:00+09:00&start-max=2009-06-01T00:00:00+09:00
("+"を"%2B"にURLエンコードする必要あり)。
繰り返しの予定
繰り返しの予定を、展開した状態で取得する場合には、singleeventsにtrueを指定します(デフォルト:false)。さらに展開する範囲は、recurrence-expansion-startとrecurrence-expansion-endで指定します。多分。。
最大件数
max-resultsで指定します(デフォルトは25件)。
まとめ
IT勉強会カレンダーから5月の東京で開催されるイベントを開催日順に100件取得する場合のURLには以下のようになります。
http://www.google.com/calendar/feeds/fvijvohm91uifvd9hratehf65k%40group.calendar.google.com/public/full?orderby=starttime&sortorder=a&max-results=100&q=[東京]&start-min=2009-05-01T00:00:00+09:00&start-max=2009-06-01T00:00:00+09:00
Queryを使う
URLを直接組み立てるのではなく、Query(CalendarQuery)を使うこともできます。
String eventFeedUrl = "http://〜"; CalendarQuery query2 = new CalendarQuery(new URL(eventFeedUrl)); query.setMaxResults(50); query.setMaximumStartTime(com.google.gdata.data.DateTime.parseDateTime("2009-06-01T00:00:00+09:00")); query.setMinimumStartTime(com.google.gdata.data.DateTime.parseDateTime("2009-05-01T00:00:00+09:00")); query.addCustomParameter(new Query.CustomParameter("orderby", "starttime")); query.addCustomParameter(new Query.CustomParameter("sortorder", "d")); query.addCustomParameter(new Query.CustomParameter("singleevents", "false")); CalendarEventFeed resultFeed = service.query(query2, CalendarEventFeed.class); ...