6 月
24
2009
Java: Googleカレンダーから祝日を取得する
By 毒舌ベリーダンサー
Googleカレンダーに登録されている祝日を取得します。
※取得はできたけど個人または非商用の使用に限定されているので、実際は使わない。。
| try { // カレンダーのURL URL feedUrl = new URL("http://www.google.com/calendar/feeds/outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com/private/full"); CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0"); // ユーザー認証 myService.setUserCredentials(mailAddress, password); // 2009年の祝日を取得 CalendarQuery myQuery = new CalendarQuery(feedUrl); myQuery.setMinimumStartTime(DateTime.parseDateTime("2009-01-01T00:00:00")); myQuery.setMaximumStartTime(DateTime.parseDateTime("2009-12-31T23:59:59")); // 選択したカレンダー(urlで指定)に登録されているイベントを取得して表示する CalendarEventFeed resultFeed = myService.query(myQuery, CalendarEventFeed.class); List entries = resultFeed.getEntries(); for( CalendarEventEntry entry: entries ) { System.out.println( entry.getTitle().getPlainText() ); List times = entry.getTimes(); for( When time: times ) { System.out.println( time.getStartTime().toString() ); } } } catch(Exception e) { e.printStackTrace(); } |
・gdata\java\lib\gdata-calendar-2.0.jar
・gdata\java\lib\gdata-client-1.0.jar
・gdata\java\lib\gdata-core-1.0.jar
・gdata\java\deps\google-collect-1.0-rc1.jar
コメントする

