【问题标题】:Retrieve info about a in-app purchase subscription of Google Play via API通过 API 检索有关 Google Play 应用内购买订阅的信息
【发布时间】:2018-11-05 23:10:04
【问题描述】:

调用 Google API 收到此消息:

    {
  "error": {
    "errors": [
      {
        "domain": "androidpublisher",
        "reason": "permissionDenied",
        "message": "The current user has insufficient permissions to perform the requested operation."
      }
    ],
    "code": 401,
    "message": "The current user has insufficient permissions to perform the requested operation."
  }
}

或此错误消息(添加):

{
 "error": {
  "errors": [
   {
    "domain": "androidpublisher",
    "reason": "projectNotLinked",
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
   }
  ],
  "code": 403,
  "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
 }
}

我遵循我发现的所有迹象,但一直出现此错误。


在我的系统上

我的代码

        try {
            ini_set('max_execution_time', 3000);
            $client = new Google_Client();

            if ($credentials_file = $this->checkServiceAccountCredentialsFilePlay()) {
                // set the location manually
                $client->setAuthConfig($credentials_file);
            } elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
                // use the application default credentials
                $client->useApplicationDefaultCredentials();
            } else {
                $rv= "missingServiceAccountDetailsWarning()";
                return [$rv];
            }

            $client->addScope("https://www.googleapis.com/auth/androidpublisher");
            $serviceAndroidPublisher = new \Google_Service_AndroidPublisher($client);
            $servicePurchaseSubscription = $serviceAndroidPublisher->purchases_subscriptions;

            $rv = $servicePurchaseSubscription->get(
                "com.my.app",
                "sub1month",
                "ajgbkxxxxxxxxx.AO-J1OxTOKENTOKENTOKEN-"
            );

        } catch (\Exception $e) {
            return $e->getMessage();
        }

凭证文件

{
  "type": "service_account",
  "project_id": "project-id",
  "private_key_id": "abababababababababababababababababa",
  "private_key": "-----BEGIN PRIVATE KEY-----KEYBASE64=\n-----END PRIVATE KEY-----\n",
  "client_email": "google-play-account@project-id.iam.gserviceaccount.com",
  "client_id": "123450000000000000000",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-play-account%40project-id.iam.gserviceaccount.com"
}

在 GOOGLE PLAY 控制台上

我将项目链接到 google play 控制台

我将服务帐户添加到 google play 控制台

它出现在 google play 控制台的用户菜单中

我给了他所有的许可:


在 GOOGLE API 开发者控制台上

添加仅供参考:我的“项目 ID”在一个组织下。

在谷歌开发者控制台中,我向服务帐户授予了所有可能的权限:

当然,我已经启用了 google Play Android Developer Api(显示我的失败):

【问题讨论】:

  • 嗨,我在这里遇到了同样的问题。我能够阅读 InApp 产品列表,但无法阅读用户订阅购买详细信息。我可以知道您是如何解决您的问题的吗?谢谢。
  • @LUMICYAN 我已经联系了谷歌支持 :)

标签: php google-api-php-client google-play-developer-api in-app-subscription


【解决方案1】:

我遇到了同样的问题。

在我的例子中,我使用谷歌应用引擎 (python) 作为后端服务。一开始,我在 Google Play Console 中链接了一个新的 Google 云项目。我不完全确定这是否是我收到 401“权限不足”错误的主要原因,但是在将链接项目切换到我的云项目(我用于应用程序引擎)之后,它在第二天工作。切换帐户后,我立即收到 403 'projects not linked' 错误。所以,我猜谷歌不会立即识别出链接项目的变化,你需要等待几个小时。

如果您使用的是应用引擎,则必须确保应用引擎的默认服务帐户具有 JSON 凭据文件。它不是默认创建的。

这是python代码:

        if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
            # production environment
            credentials = oauth2client.contrib.appengine.AppAssertionCredentials(scope='https://www.googleapis.com/auth/androidpublisher')
            http = credentials.authorize(httplib2.Http(memcache))
            response = googleapiclient.discovery.build('androidpublisher', 'v3').purchases().subscriptions()\
                .get(packageName=package_name, subscriptionId=subscription.product_id, token=subscription.token)\
                .execute(http)
        else:
            # local environment
            # setting the scope is not needed because the api client handles everything automatically
            credentials = google.oauth2.service_account.Credentials.from_service_account_file('local_dev.json')
            response = googleapiclient.discovery.build('androidpublisher', 'v3', credentials=credentials).purchases().subscriptions()\
                .get(packageName=package_name, subscriptionId=subscription.product_id, token=subscription.token)\
                .execute()

【讨论】:

  • 在我的情况下是谷歌的问题,我要求支持并解决它:)
猜你喜欢
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 2021-12-21
  • 2011-12-26
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 2021-01-17
相关资源
最近更新 更多