2011-12-29 130 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来获得访问令牌是什么,请确保您的范围设置为谷歌日历。将您的刷新令牌保存在某处,然后您可以访问所有您想要的内容