Google OAuth2 トークンを取得する with Go
GAE/Go をちょいちょい触っている。
その中の Pull queue を試そうとしたとき、OAuth2 のトークンが必要になったので取得したメモ。
手順
- Google Could Platform の API Manager から認証情報(ClientID, Secret)をつくる
- 下記コマンドを叩く。
[utahta@mbp google-oauth2]% go run oauth2_token.go Input ClientID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com Input Secret: XXXX-XXXXXXXXXXXXXXXXXXXXXX Input Scopes: https://www.googleapis.com/auth/taskqueue,https://www.googleapis.com/auth/taskqueue.consumer Start Execute API ブラウザで以下のURLにアクセスし、認証して下さい。 https://accounts.google.com/o/oauth2/authxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Input auth code: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX token is saved to token.json [utahta@mbp google-oauth2]% cat token.json {"access_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","token_type":"Bearer","refresh_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","expiry":"2016-08-16T21:46:52.012038137+09:00"}
ソースコード
トークンめも
リフレッシュトークンは 1 クライアント 25 個まで。それ以上は古いものから消えていく。
Using OAuth 2.0 to Access Google APIs | Google Identity Platform | Google Developers
参考
GolangでGoogle Driveにアクセスするためのトークンを取得 - Qiita
OAuth2.0によるGoogle+ APIのアクセス方法
Google APIのAccess Tokenをお手軽に取得する - Qiita