google calendarでカレンダーを作成する
基本的にはsampleについてきたCalendarFeedDemo.javaから、
不要だと思われる箇所を削っただけ。
package sample.calendar; import java.net.URL; import com.google.gdata.client.calendar.CalendarService; import com.google.gdata.data.PlainTextConstruct; import com.google.gdata.data.calendar.CalendarEntry; import com.google.gdata.data.calendar.ColorProperty; import com.google.gdata.data.calendar.HiddenProperty; import com.google.gdata.data.calendar.TimeZoneProperty; import com.google.gdata.data.extensions.Where; public class CreateCalendar { /** google calendar 基準URL */ private static final String METAFEED_URL_BASE = "http://www.google.com/calendar/feeds/"; /** マイカレンダー用アドレス */ private static final String OWNCALENDARS_FEED_URL_SUFFIX = "/owncalendars/full"; /** マイカレンダーフィード用URL */ private static URL owncalendarsFeedUrl = null; private static final String BLUE = "#2952A3"; /** ユーザー名 */ static final String USER_NAME = "xxxxxxxx@gmail.com"; /** パスワード */ static final String USER_PASSWORD = "xxxxxxxx"; /** * カレンダーを作成します。 * * @param service * CalendarServiceオブジェクト * @return 作成されたCalendarEntryオブジェクト * @throws Exception */ private static CalendarEntry createCalendar(CalendarService service) throws Exception { System.out.println("カレンダーを作成します。"); // カレンダーオブジェクトを初期化 CalendarEntry calendar = new CalendarEntry(); calendar.setTitle(new PlainTextConstruct("マイカレンダー1")); calendar.setSummary(new PlainTextConstruct("サンプルの説明")); calendar.setTimeZone(new TimeZoneProperty("Asia/Tokyo")); calendar.setHidden(HiddenProperty.FALSE); calendar.setColor(new ColorProperty(BLUE)); calendar.addLocation(new Where("", "", "Toyama")); // カレンダーを追加します。 CalendarEntry newEntry = service.insert(owncalendarsFeedUrl, calendar); return newEntry; } public static void main(String[] args) { try { // URLオブジェクトを作成 owncalendarsFeedUrl = new URL(METAFEED_URL_BASE + USER_NAME + OWNCALENDARS_FEED_URL_SUFFIX); // カレンダーサービスに接続 CalendarService service = new CalendarService( "chaos-CreateCalendarSample-1"); service.setUserCredentials(USER_NAME, USER_PASSWORD); // カレンダーを作成 createCalendar(service); } catch (Exception e) { e.printStackTrace(); } } }
コンストラクタ:CalendarServiceの引数は文字列で
[company-id]-[app-name]-[app-version]
らしいので、テキトーに変更。
(例外処理とかはテキトーです。)