无法从 Google Play Android Developer API 获取订阅详细信息
Unable to fetching subscription detail from Google Play Android Developer API
我正在尝试使用 Google API 的 Java 客户端库来获取有关用户在我的 android 应用中购买的订阅的信息。然后我得到了这个错误:
{
"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."
}
我正在尝试这些步骤:
- 转到https://console.cloud.google.com
- 创建项目(或select现有项目)
- 创建角色为 Pub/Sub Admin
的服务帐户
- 转到 https://console.cloud.google.com/apis/library 并搜索“Google
播放 Android 开发者 API"
- 启用API
- 转到https://play.google.com/apps/publish
- 转到设置 > 开发者帐户 > API 访问
- Link 您在步骤 2 中创建的项目
- 将显示您在第 3 步中创建的服务帐户
- 在 play console 中授予对应用程序的财务权限
- 等待至少 24 小时以使更改生效。
我正在尝试这段代码:
httpTransport = new com.google.api.client.http.javanet.NetHttpTransport();
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
String applicationName = "App name";
String packageName = "com.example.xxx";
final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);
AssetManager am = getAssets();
InputStream inputStream = am.open("key1.p12");
File file = createFileFromInputStream(inputStream);
Log.d(TAG, "file : " + file);
if(file != null){
int SDK_INT = android.os.Build.VERSION.SDK_INT;
if (SDK_INT > 8) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("pp-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes)
//.setServiceAccountId("practice-presto-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(file).build();
AndroidPublisher pub = new AndroidPublisher.Builder
(httpTransport, jsonFactory, credential)
.setApplicationName(applicationName)
.build();
final AndroidPublisher.Purchases.Subscriptions.Get get =
pub.purchases().subscriptions().get(packageName, "sub_monthly_pro", "pcehicpbjhcdnjockiniaokh.AO-J1OxsJtLehF3z_naoXR4LE0jqiXrABAPYiZMNRMZO5jnKI9gnyHmPP7INtcc2kyptNKP_HM6MjEPQfmYWmJ8R_geonsLqMXA9TLsozqNexh-FxSvQFDZSUTgBW_azvdAJPLxPFuKd");
final SubscriptionPurchase purchase = get.execute();
Log.d(TAG, "Found google purchase item " + purchase.toPrettyString());
}
}
我正在使用测试应用内购买模式。
我想在更新订阅计划后获取最新的订阅收据。
我在 24 小时后检查有错误。不过之后我又隔了两天再检查没有错误,数据已经收到了。
在 Google API 控制台帐户中要做的事情
- 创建项目(或select现有项目)
- 创建角色为 Pub/Sub Admin
的服务帐户
- 从API库
启用“Google播放Android开发者API”
在 Google 玩控制台帐户时要做的事情
- 转到设置 > 开发者帐户 > API 访问
- Link 使用您在步骤 2 中创建的服务帐户的项目
- 在 Play 控制台中向应用程序授予财务权限,并等待至少 48 小时以使更改生效。
其他要记住的事情
- 您的应用需要上传到控制台帐户(alpha、beta、production)中的轨道之一,并获得计费库和许可。
- 您的订阅应该有效
- 创建产品后等待几个小时
我正在尝试使用 Google API 的 Java 客户端库来获取有关用户在我的 android 应用中购买的订阅的信息。然后我得到了这个错误:
{
"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."
}
我正在尝试这些步骤:
- 转到https://console.cloud.google.com
- 创建项目(或select现有项目)
- 创建角色为 Pub/Sub Admin 的服务帐户
- 转到 https://console.cloud.google.com/apis/library 并搜索“Google 播放 Android 开发者 API"
- 启用API
- 转到https://play.google.com/apps/publish
- 转到设置 > 开发者帐户 > API 访问
- Link 您在步骤 2 中创建的项目
- 将显示您在第 3 步中创建的服务帐户
- 在 play console 中授予对应用程序的财务权限
- 等待至少 24 小时以使更改生效。
我正在尝试这段代码:
httpTransport = new com.google.api.client.http.javanet.NetHttpTransport();
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
String applicationName = "App name";
String packageName = "com.example.xxx";
final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);
AssetManager am = getAssets();
InputStream inputStream = am.open("key1.p12");
File file = createFileFromInputStream(inputStream);
Log.d(TAG, "file : " + file);
if(file != null){
int SDK_INT = android.os.Build.VERSION.SDK_INT;
if (SDK_INT > 8) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("pp-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes)
//.setServiceAccountId("practice-presto-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(file).build();
AndroidPublisher pub = new AndroidPublisher.Builder
(httpTransport, jsonFactory, credential)
.setApplicationName(applicationName)
.build();
final AndroidPublisher.Purchases.Subscriptions.Get get =
pub.purchases().subscriptions().get(packageName, "sub_monthly_pro", "pcehicpbjhcdnjockiniaokh.AO-J1OxsJtLehF3z_naoXR4LE0jqiXrABAPYiZMNRMZO5jnKI9gnyHmPP7INtcc2kyptNKP_HM6MjEPQfmYWmJ8R_geonsLqMXA9TLsozqNexh-FxSvQFDZSUTgBW_azvdAJPLxPFuKd");
final SubscriptionPurchase purchase = get.execute();
Log.d(TAG, "Found google purchase item " + purchase.toPrettyString());
}
}
我正在使用测试应用内购买模式。
我想在更新订阅计划后获取最新的订阅收据。
我在 24 小时后检查有错误。不过之后我又隔了两天再检查没有错误,数据已经收到了。
在 Google API 控制台帐户中要做的事情
- 创建项目(或select现有项目)
- 创建角色为 Pub/Sub Admin 的服务帐户
- 从API库 启用“Google播放Android开发者API”
在 Google 玩控制台帐户时要做的事情
- 转到设置 > 开发者帐户 > API 访问
- Link 使用您在步骤 2 中创建的服务帐户的项目
- 在 Play 控制台中向应用程序授予财务权限,并等待至少 48 小时以使更改生效。
其他要记住的事情
- 您的应用需要上传到控制台帐户(alpha、beta、production)中的轨道之一,并获得计费库和许可。
- 您的订阅应该有效
- 创建产品后等待几个小时