【发布时间】:2019-03-21 13:35:41
【问题描述】:
我遵循了这个教程:https://medium.com/@infinitesimal_/doing-android-purchase-validation-api-v3-in-java-5c46fc837368
但我不能让它工作!我能得到的只有这个:
{
"code" : 401,
"errors" : [ {
"domain" : "androidpublisher",
"message" : "The current user has insufficient permissions to perform the requested operation.",
"reason" : "permissionDenied"
} ],
"message" : "The current user has insufficient permissions to perform the requested operation."
}
这是我的java代码:
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
String applicationName = "My App";
String packageName = "com.my.package";
final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("myAccoutId")
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(
new File("/my/path"))
.build();
AndroidPublisher pub = new AndroidPublisher.Builder
(httpTransport, jsonFactory, credential)
.setApplicationName(applicationName)
.build();
final AndroidPublisher.Purchases.Products.Get get =
pub.purchases()
.products()
.get(packageName, "name", "transactionId");
final ProductPurchase purchase = get.execute();
System.out.println("Found google purchase item " + purchase.toPrettyString());
我创建了一个服务帐户并赋予了所有者角色。我去了谷歌播放控制台,在用户和权限中我也让这个服务帐户成为管理员。
【问题讨论】:
-
您解决了这个问题吗?你能分享你的解决方案吗?谢谢。
-
对不起,尝试了很多,但我无法解决这个问题。我使用交易 ID 进行了简单的验证。它有所帮助,但仍然存在一些问题。
-
该代码在服务帐户创建后 2 天生效,请试一试。
-
已弃用已回答的方法现在使用此方法stackoverflow.com/a/57943483/5232267
标签: android in-app-purchase service-accounts google-play-console google-play-developer-api