【Authentication and Authorization for Google APIs】-  Using OAuth 2.0 to Access Google APIs

一開始在看 Google apis 時,還真的有些搞不懂。 但 Google 寫的文件,還真的都滿清楚的。

當然要做 Google 登入,一開始是要建立 API 的 Key (當然 Yahoo 也是如此!!)

先決條件!! Google 的帳號一定要有的呀. 

登入 Google 後可到以 Google project 頁設定,並取得 API 的 Key  (反觀 Yahoo API Key 的申請真的是差很大!!)

Google project 頁:  https://code.google.com/apis/console

連到 apis console 後,點選 API Access 就可以產生 API 的 Key 嘍!!

(不需像 Yahoo 那樣,需要認証 Domain,一整個超容易超方便的。) 

由於我是使用 OAuth 2.0 所以是看 OAuth 的文件

文件網址: http://code.google.com/intl/zh-TW/apis/accounts/docs/OAuth2.html

真的覺得 Google API 超直覺性的,若操作到這邊!! 你的 Google OAuth 己經完成 8 成了。

只需了解各參數的用途,將參數補上就完成嘍。

範例:

https://accounts.google.com/o/oauth2/auth?
scope=## 登入成功後取得的資料(備註1) ##&
client_id=## api console 中的 client id ##&
redirect_uri=<?=urlencode("http://www.yoursite.com.tw")?>&
response_type=## 回傳的 type (code or token) ##

scope 主要是要得知 該 API 所要讀取 Google 的那些資料。

大多需要取得的資料為「https://www.google.com/m8/feeds/」

備註 1:  http://code.google.com/intl/zh-TW/apis/gdata/faq.html#AuthScopes

文章標籤
全站熱搜
創作者介紹
創作者 王小明 的頭像
王小明

王小明的部落格

王小明 發表在 痞客邦 留言(0) 人氣(0)