更新时间:2023-02-14 14:11:47
添加以下依赖项
compile "com.google.apis:google-api-services-androidpublisher:v3-rev103-1.25.0"
compile "com.google.auth:google-auth-library-oauth2-http:0.17.1"
然后从Google Cloud Console 此处启用Google Developer Play Api库
Then enable Google Developer Play Api library from Google Cloud Console here
使用凭据创建具有角色Pub/Sub Admin
的服务帐户密钥并保存json文件
In credentials Create service account key with role Pub/Sub Admin
and save json file
在Google开发者控制台中此处.
在Settings >> Developer Account >> API Access
中,链接您的应用.
In Google developers Console here.
In Settings >> Developer Account >> API Access
link your app.
然后在代码中执行以下操作以获取订阅信息.
Then in code do following to get subscription info.
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("<service-account-key-file>.json")).createScoped(AndroidPublisherScopes.ANDROIDPUBLISHER);
AndroidPublisher pub = new AndroidPublisher.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
new HttpCredentialsAdapter(credentials)
).setApplicationName("<app-name>").build();
SubscriptionPurchase purchase = pub.purchases().subscriptions().get(
"<app-package>",
"<subscription-id>",
"<purchase-token>"
).execute();
println(purchase);
注意:如果出现此错误:
Note: if you get this error:
当前用户的权限不足,无法执行所请求的 操作.
The current user has insufficient permissions to perform the requested operation.
然后在一天后重试,因为在启用Google Play开发者API并从Google控制台创建服务帐户密钥后,您需要等待24到48小时,然后执行以下操作
Then try again after one day because after enable google play developer api and creating service account key from google console you need to wait 24 to 48 hours and also do following
从Google Play控制台转到(具有管理员访问权限):
From Google Play Console go to (with admin access):