隨筆 - 175  文章 - 202  trackbacks - 0
          <2009年7月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          第一個Blog,記錄哈哈的生活

          常用鏈接

          留言簿(16)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          Java links

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          1. 先到 google code 上下載了 api 的 lib,當然是 java client,還有好多,比如 .net , php 什么的,沒看。
          2. 去看 google data api 的 getting start,但是,那個 ant 命令執行完,會出一些 captcha 的錯誤,沒細看,估計是需要驗證碼了,api 沒跟上。
          3. 直接到 calendar 里面,把 CalendarFeedDemo執行了一下,注意,需要輸入用戶名和密碼,用戶名是 aaa@gmail.com 這樣的,但發現這個不是我要的,我要的只是增加個 event 而已。
          4. 執行 EventFeedDemo,jump這個才是我要的,簡化了一下,只要能增加一個定時的 event,并有提醒,就夠了。

          代碼在下面,連包名都沒改:
           1 
           2 package sample.calendar;
           3 
           4 import java.io.IOException;
           5 import java.net.URL;
           6 import java.util.Calendar;
           7 import java.util.GregorianCalendar;
           8 import java.util.TimeZone;
           9 
          10 import com.google.gdata.client.calendar.CalendarService;
          11 import com.google.gdata.data.DateTime;
          12 import com.google.gdata.data.PlainTextConstruct;
          13 import com.google.gdata.data.calendar.CalendarEventEntry;
          14 import com.google.gdata.data.extensions.Reminder;
          15 import com.google.gdata.data.extensions.When;
          16 import com.google.gdata.data.extensions.Reminder.Method;
          17 import com.google.gdata.util.ServiceException;
          18 
          19 public class HahaCalendar {
          20     private static URL eventFeedUrl;
          21     private static final String METAFEED_URL_BASE = "http://www.google.com/calendar/feeds/";
          22     private static final String EVENT_FEED_URL_SUFFIX = "/private/full";
          23 
          24     public static void main(String[] args) throws ServiceException, IOException {
          25         String username = "username@gmail.com";
          26         eventFeedUrl = new URL(METAFEED_URL_BASE + username + EVENT_FEED_URL_SUFFIX);
          27         CalendarService myService = new CalendarService("haha calendar");
          28         myService.setUserCredentials(username, "password");
          29         CalendarEventEntry singleEvent = createSingleEvent(myService, "每天背單詞""單詞1,單詞2");
          30         System.out.println("Successfully created event " + singleEvent.getTitle().getPlainText());
          31     }
          32 
          33     private static CalendarEventEntry createSingleEvent(CalendarService service, String eventTitle, String eventContent)
          34             throws ServiceException, IOException {
          35         CalendarEventEntry entry = new CalendarEventEntry();
          36         entry.setTitle(new PlainTextConstruct(eventTitle));
          37         entry.setContent(new PlainTextConstruct(eventContent));
          38         Calendar calendar = new GregorianCalendar();
          39         calendar.add(Calendar.MINUTE, 10);
          40         DateTime startTime = new DateTime(calendar.getTime(), TimeZone.getDefault());
          41         calendar.add(Calendar.MINUTE, 60);
          42         DateTime endTime = new DateTime(calendar.getTime(), TimeZone.getDefault());
          43         When eventTimes = new When();
          44         eventTimes.setStartTime(startTime);
          45         eventTimes.setEndTime(endTime);
          46         entry.addTime(eventTimes);
          47         addReminder(entry);
          48         return service.insert(eventFeedUrl, entry);
          49     }
          50 
          51     private static void addReminder(CalendarEventEntry myEntry) {
          52         Reminder reminder = new Reminder();
          53         reminder.setMinutes(5);
          54         reminder.setMethod(Method.SMS);
          55         myEntry.getReminder().add(reminder);
          56     }
          57 }
          58 

          想用的注意,把上面的用戶名和密碼改成自己的。


          posted on 2009-07-19 13:04 哈哈的日子 閱讀(2303) 評論(4)  編輯  收藏 所屬分類: Java

          FeedBack:
          # re: 試了一下 Google Calendar API,給自己每天定個任務。 2009-08-13 10:05 BlueSunshine
          回復一下  回復  更多評論
            
          # re: 試了一下 Google Calendar API,給自己每天定個任務。[未登錄] 2009-08-13 10:06 lala
          再回復一下  回復  更多評論
            
          # re: 試了一下 Google Calendar API,給自己每天定個任務。 2009-11-02 14:43 eric shen
          您好啊,java我到是不懂,不過我用 Google Calendar的  回復  更多評論
            
          # re: 試了一下 Google Calendar API,給自己每天定個任務。 2009-12-12 10:58 weiwx
          怎么執行啊? 沒有可執行的文件阿?我對java不是很懂  回復  更多評論
            
          主站蜘蛛池模板: 赤城县| 洞头县| 利川市| 文山县| 诸暨市| 上蔡县| 茂名市| 桑植县| 菏泽市| 南乐县| 讷河市| 定兴县| 名山县| 禹州市| 洪洞县| 黄平县| 莲花县| 论坛| 炉霍县| 集安市| 恩施市| 永德县| 高碑店市| 红原县| 姚安县| 霍州市| 阳山县| 天门市| 福泉市| 西吉县| 泽州县| 济阳县| 温州市| 库伦旗| 朔州市| 广河县| 北流市| 金湖县| 江华| 日土县| 双鸭山市|