2011-12-29 76 views
0

如何在Android上使用新的API訪問谷歌日曆? 使用GData API與我可以寫這樣的代碼:使用谷歌API訪問谷歌日曆

CalendarService myService = new CalendarService("CalendarService"); 
myService.setUserCredentials("[email protected]", "yourPassword"); 
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full"); 
CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class); 
Log.d(TAG,"Your calendars:"); 
for (int i = 0; i < resultFeed.getEntries().size(); i++) { 
    CalendarEntry entry = resultFeed.getEntries().get(i); 
    Log.d(TAG,entry.getTitle().getPlainText()); 
} 

但我不能在Android上使用這樣的代碼,因爲SAX異常。請告訴我如何使用new V3 api以這種方式授權登錄名和密碼。

回答

1

你不能與V3的用戶名和密碼認證,它採用的oauth2

你需要做的就是使用的OAuth2來獲得訪問令牌是什麼,請確保您的範圍設置爲谷歌日曆。將您的刷新令牌保存在某處,然後您可以訪問所有您想要的內容