Integrated
  • Introduction
  • FTP伺服器架設
  • PHP-json格式的轉換
  • Google API
  • Meta Tag
  • 虛擬網址的設定
Powered by GitBook
On this page
  • 開新專案
  • 開啟功能
  • 抓取Access_Token
  • 取得會員資料

Was this helpful?

Google API

PreviousPHP-json格式的轉換NextMeta Tag

Last updated 5 years ago

Was this helpful?

開新專案

先註冊一個google帳號,然後到開一個新專案,

開啟功能

開啟Google+API功能

抓取Access_Token

https://accounts.google.com/o/oauth2/auth?response_type=token&client_id=344630307125-hohabs1ktlmagr9f2lokergoruui2tdq.apps.googleusercontent.com&redirect_uri=http://stage-tw-member.iscarmg.com/test&scope=https://www.googleapis.com/auth/userinfo.profile + https://www.googleapis.com/auth/userinfo.email

?後面接的是Get參數,

第一個respose_type,可以要他們回傳token or code

第二個client_id,就是剛剛新增的專案的client_id

第三個redirect_uri,就是要值回傳到哪個頁面

第四個scope,意思是你要利用這個token存取哪些Google API

然後將你串好的這串路徑送出,他就會根據你的需求去跟google要值,然後傳到你的回傳頁

http://stage-tw-member.iscarmg.com/test#access_token=ya29.GmBxBLkvoCf0q9-f1gSsiJXP5Tg4E3lCJ8ex_oz6VrFxjRorY1FHv6Fg1vaUBoIvbk0mM4gcvd5JNrAcay1aVTBTXbg1daiRZgOu0yc9N4yLrQSeHTc0m3lxfBRWKzc05S0&token_type=Bearer&expires_in=3600

設法將access_token切割出來,先將"#"之前的路徑切掉,然後再分割後面的字串變成陣列,取第一個陣列,就可以拿這個access_token去跟google要會員資料囉。

取得會員資料

https://www.googleapis.com/oauth2/v3/userinfo?alt=json&access_token=ya29.GlxxBELlBAB6aD32RKDp5Ly58dgx8ZPUDXG3MK0joKfp9JtrW3CWRbE4FWu37ggimEDbB8CEAmLjcYc3aFit7aaIoSFimiY-wNOvjZB2rdx_3WboonZY4C_D5zWU9w

?後面接的是Get參數,

第一個alt,為待會會員資料回傳的格式

第二個access_token,就是剛剛跟google要到的token

送出以後就會得到以下json格式的會員資料

{
 "sub": "會員ID",
 "name": "全名",
 "given_name": "last name",
 "family_name": "first name",
 "profile": "google+部落格",
 "picture": "頭像路徑",
 "email": "信箱",
 "email_verified": 是否已經信箱驗證,
 "gender": "性別",
 "locale": "地區"
}
GoogleCloudPlatfor