LoginSignup
1
0

More than 3 years have passed since last update.

android 課金レシート検証するためにリフレッシュトークン取得がやっと理解できた

Posted at

リフレッシュトークンが必須!!

リフレッシュトークンを取得するまでの流れ

OAuth 2.0 クライアント IDに、タイプ「ウェブアプリケーション」のクライアントIDを作成する
リダイレクト先をhttp://localhost でもなんでもいいから登録しておくこと

1.codeを取得する

ブラウザのアドレスに以下を記入する。

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://localhost&client_id=1097990115894-an30hkodeibai45l87k2l0nun6h391e5.apps.googleusercontent.com

URLに以下が表示されるのでコピーしておくcode=のところ。

http://localhost?code=4/uQHoIVqMTRTE4B9yD4xD6pLc9lQjFhip5MgKQzY1R-NL2t7vorjgxDph-Uus2pF6LR_SB4QPU2XfQLdXmjcgNJQ&scope=https://www.googleapis.com/auth/androidpublisher

2.codeを使用してリフレッシュトークンを取得する

curl -v POST 'https://accounts.google.com/o/oauth2/token' -d 'grant_type=authorization_code&code=4/uQHoIVqMTRTE4B9yD4xD6pLc9lQjFhip5MgKQzY1R-NL2t7vorjgxDph-Uus2pF6LR_SB4QPU2XfQLdXmjcgNJQ&client_id=1097990115894-an30hkodeibai45l87k2l0nun6h391e5.apps.googleusercontent.com&client_secret=ENCia4n6tObNfAXgLUsx4w_H&redirect_uri=https://api-8038439892644900029-39912.firebaseapp.com/__/auth/handler'

以下のメッセージが出ればOK
リフレッシュトークンを覚えておくこと。

{
  "access_token": "ya29.Il-2B7gDYJjzX2GqI1xNIDG3Fyk3HspvgQ2o9yn3T7ceIGY2d76VZt3LAOluaKkQYjbiHIbvn----JfrpU-cK7tzP-tzxeVja9ijJQSXFCNIz4Y9Xv2mvU0VcvEggkWW6Q",
  "expires_in": 3600,
  "refresh_token": "1//0eGLq8_AA_TLxCgYIARAAGA4SNwF-L9Ir1DDfSziuMlV1v9hTQtPzKcbcUQTLo8C8kfo4zdlCg_TA5K4XY9RkM-t5QWtsKATio2o",
  "scope": "https://www.googleapis.com/auth/androidpublisher",
  "token_type": "Bearer"
* Connection #1 to host accounts.google.com left intact
}

ここで大事なのは、うまく行かない場合、redirect_uriやscopeを間違えた場合、1の作業からやる必要がある。codeは毎回ことなるため。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0