LoginSignup
9
9

More than 3 years have passed since last update.

ユーザーの定期購読情報をGoogle Play Developer APIで取得するためのデータメモ

Last updated at Posted at 2019-02-07

〇概要

Android定期購読の情報をGoogle Play Developer APIで取得するためのデータがどこに記載されているのか忘れやすいのでメモ。
OAuthやGoogle Play Developer APIの初期設定方法ではないので、ご了承ください。

〇流れ

OAuthにてアクセストークン取得
https://developers.google.com/android-publisher/authorization

Google Play Developer APIのPurchases.productsのgetにて定期購読情報取得
https://developers.google.com/android-publisher/api-ref/purchases/subscriptions

〇アクセストークン取得に必要なデータ

・クライアントID(client_id)
(例)72347・・・apps.googleusercontent.com
Google APIs[https://code.google.com/apis/console]
のプロジェクト選択→左上のナビゲーションメニューから「APIとサービス」を選択→「認証情報」→「OAuth 2.0 クライアント ID」に記載

・クライアントシークレット(client_secret)
(例)gNFim・・・73hJK
「OAuth 2.0 クライアント ID」の名前をクリック→「クライアント シークレット」に記載

・リダイレクトURI(ridirect_uri)
(例)http://xxx.co.jp/oauth2callback
「OAuth 2.0 クライアント ID」の名前をクリック→「承認済みのリダイレクト URI」に記載

・リフレッシュトークン(refresh_token)
(例)1/nAEL-vLKKEWE・・・7yE
クライアントIDとリダイレクトURLでAPIを叩いて取得(一度取得したら使いまわし)
curl -F "scope=https://www.googleapis.com/auth/androidpublisher" -F "response_type=code" -F "access_type=offline" -F "redirect_uri=..." -F "client_id=..." "https://accounts.google.com/o/oauth2/auth"
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=...&client_id=...
Googleにログインして、付属するパラメータからリダイレクトIDを取得

・アクセストークン
(例)ya15.FekwlCKD・・・8EK
クライアントIDとクライアントシークレットとリフレッシュトークンを利用してAPIを叩いて取得
curl -F "client_id=..." -F "client_secret=..." -F "grant_type=refresh_token" -F "refresh_token=..." "https://accounts.google.com/o/oauth2/token"
(注)1時間で無効になるので注意

〇Purchases.productsのgetにて定期購読情報取得

・packageName
・subscriptionId(productId)
・token(purchaseToken)
に関してはレシートのJSON情報から抜き出す。

curl "https://www.googleapis.com/androidpublisher/v3/applications/__packageName__/purchases/subscriptions/__subscriptionId__/tokens/__token__?access_token=..."

〇取得データ

{
"kind": "androidpublisher#subscriptionPurchase",
"startTimeMillis": long,
"expiryTimeMillis": long,
"autoRenewing": boolean,
"priceCurrencyCode": string,
"priceAmountMicros": long,
"countryCode": string,
"developerPayload": string,
"paymentState": integer,
"cancelReason": integer,
"userCancellationTimeMillis": long,
"cancelSurveyResult": {
"cancelSurveyReason": integer,
"userInputCancelReason": string
},
"orderId": string,
"linkedPurchaseToken": string,
"purchaseType": integer,
"profileName": string,
"emailAddress": string,
"givenName": string,
"familyName": string,
"profileId": string
}

9
9
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
9
9