本文整理新浪微博開放平台 OAuth 2.0 授權登入的標準流程,供開發者快速接入「微博登入」功能。
App Key(Client ID)與 App Secret(Client Secret),並設定授權回調頁(Redirect URI)。code。
https://api.weibo.com/oauth2/authorize?client_id={App Key}&redirect_uri={Redirect URI}&response_type=code&scope=all
Redirect URI 並附上 code 參數。code 向微博請求 Access Token。
POST https://api.weibo.com/oauth2/access_token
client_id={App Key}&client_secret={App Secret}&grant_type=authorization_code&redirect_uri={Redirect URI}&code={CODE}
成功回傳 JSON 包含 access_token、expires_in、uid 等。users/show.json 等介面獲取用戶資料。
GET https://api.weibo.com/2/users/show.json?access_token={ACCESS_TOKEN}&uid={UID}
uid 與本地用戶表關聯,完成登入狀態建立。refresh_token)。