繁体   English   中英

通过API检索有关Google Play的应用内购买订阅的信息

[英]Retrieve info about a in-app purchase subscription of Google Play via API

调用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."
  }
}

或此错误消息( ADDED ):

{
 "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 Developer Console中,我将所有可能的权限授予了该服务帐户: 在此处输入图片说明

当然,我已经启用了Google Play Android开发者Api(显示我的失败): 在此处输入图片说明

我有同样的问题。

就我而言,我使用的是Google App Engine(python)作为后端服务。 首先,我在Google Play控制台中链接了一个新的Google云项目。 我不完全确定这是否是我收到401“权限不足”错误的主要原因,但是在将链接的项目切换到我的云项目(用于应用程序引擎)后,第二天它就可以工作了。 切换帐户后,我立即收到403个“未链接的项目”错误。 因此,我猜想Google无法立即识别出所链接项目的更改,因此您需要等待几个小时。

如果您使用的是App Engine,则必须确保您的App Engine的默认服务帐户具有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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM