我正在使用Google API Client Library for Java来获取有关在我的Android应用程序中购买的用户订阅的信息.这就是我现在正在做的事情:
HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(GOOGLE_CLIENT_MAIL)
.setServiceAccountScopes("https://www.googleapis.com/auth/androidpublisher")
.setServiceAccountPrivateKeyFromP12File(new File(GOOGLE_KEY_FILE_PATH))
.build();
Androidpublisher publisher = new Androidpublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).
setApplicationName(GOOGLE_PRODUCT_NAME).
build();
Androidpublisher.Purchases purchases = publisher.purchases();
Get get = purchases.get("XXXXX", subscriptionId, token);
SubscriptionPurchase subscripcion = get.execute(); //Exception returned here
Run Code Online (Sandbox Code Playgroud)
GOOGLE_CLIENT_MAIL是来自Google控制台的API Access的电子邮件地址.
GOOGLE_KEY_FILE_PATH是从API Access下载的p12文件.
GOOGLE_PRODUCT_NAME是品牌信息的产品名称.
在Google APIS控制台中,启用了"Google Play Android Developer API"服务.
我得到的是:
{
"code" : 401,
"errors" : [ {
"domain" : "androidpublisher",
"message" …Run Code Online (Sandbox Code Playgroud)