Create Google API Keys

最近某專案對於第三方 API 有相當多需求,我負責處理其中三個…. Google, Twitter, Yahoo…
不過我好久沒接 Google API 了,又重看了一下文件。簡單筆記一下。

要使用 Google API 要申 Google 申請授權,並取得相關的金鑰 (Key),首先到 Google API Console 登入。

如果之前都沒有創建 projects 的話才會看到這畫面,點下去就進入 console 了。

首先點選左側選單的 APIs,在這裡選取需要用的 API,啟動其授權。如果只需要 Google 登入功能的話,打開 Google+ API 即可。
PS. 以下畫面都是用新版的介面抓圖的。

接著到 Credentials 畫面。點選 OAuth 那欄的 Create New Client ID,根據需求選擇 Application Type,我開發 Web 為主就選第一個 Web Application,Authorized Javascript Origins 那欄填寫網案網址,Authorized Redirect URI 是填寫用來接 Google 認證回傳的網址。完成後確認離開。Google 會吐一堆奇怪的文字,像是 Client ID 之類的,先不用管它,但請不要外洩這些資訊。

接著點選下半部 Public API access 的 Create New Key,這個 Key 就是指 API key 或 Developer Key。Key 有四種選項:Server key, Browser key, Android key 和 iOS key。後兩者應該是沒有疑問的,前兩種的差異是 Server key 只用在伺服器端的流程,不應該被看到。而 Browser key 才會寫在前端的頁面裡,像是 Javascript 之類的。

下一步是要輸入允許的 IP 範圍,可以輸入多組 IP,記得把開發用、測試用、正式上線的 IP 都填入。完成後取得 Key。

最後來到左側選單的 Consent screen,這裡要填的資料便是向使用者取得授權時,使用者會看到的畫面,所以要認真寫。

到這邊就 OK 了,接下來就可以開始使用 Google API 進行開發了。


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version