2013年9月6日 星期五

google calendar api使用方法

-- brief version
ios
透過oauth2認證後,取得GTLServiceCalendar對象,便可對calendar list作query,query的流程為一個CalendarListTicket,取得list資料後,可以從calendar-entry裡面的id對calendar events作query。基本上整個calendar就只有兩個主要資料格式,calendar list and indicated calendar events list .
android
使用google play的機制取得google account,而後也是維持一個com.google.api.services.calendar.Calendar的對象,也是先取得calendar list後再對該id取得calendar內的events .
我所設計的格式都是一個叫core的物件去storage取得的資料,並且使用一個callback來更新ui,一開始取得的calendar list 出現頁面後,在經由點選取得該event lists 。
-- Detail version
ios 版
各類資料網站
https://code.google.com/apis/console
首先要上google develop申請project , 開啟calendar api的使用 會給你一組Client ID:Client secret: 是用來作oauth2.0認證的
而他推薦的library為
https://developers.google.com/google-apps/calendar/downloads?hl=zh-TW
點選ios版的 下載
需拉進HTTPFetcher OAuth2 Objects Utilities這四個資料夾 其他optional
並且拉進Service裡面你需要的google data api
code flow為
需維持GTLServiceCalendar一個對象,透過GTMOAuth2ViewControllerTouch可以透過畫面登入google id得取authenticate,傳給GTLServiceCalendar.auth .
認證過後就可以在透過他的方法取得calendar list ,
每個calendar list有subcategory events

- android 版
首先也是上android api console去註冊android需要的key ,
需要的資料為 package name , and key fingerprint SHA1
取得SHA1的方法如下
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
取的是debug key的fingerprint
註冊android key似乎需要反應時間

- importart
這邊使用google play的帳號來幫忙存取google account , 需要手機上有google play
需將google play弄成libery編譯至project內 參照下面說明
http://developer.android.com/google/play-services/setup.html
此外幾個重要的lib檔皆可參考demo裡面所附的jar檔
比較值得一提的是,整個google api應該也都是如此的flow。

沒有留言:

張貼留言