获取android订阅状态,失败403

在尝试获取android应用内订阅状态(失效date)时,出现以下错误消息:

{ "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." } } 

url是: https : //www.googleapis.com/androidpublisher/v2/applications/[packageName] / inapp/[productId] / purchases/[purchase_token]?access_token=[access_token]

它说项目ID没有链接。 我做了以下几件事:

 1. Create the project in Google Developer Console. 2. Turn on the Google Android Publisher API. 3. Link the project ID as mentioned in API access page (https://developers.google.com/android-publisher/getting_started) 4. Fill in the packageName, productId (from in app-purchase), purchase_token (from Android app) 

不知道为什么错误信息如上所示。 我尝试了OAuth2游乐场,没有运气( https://developers.google.com/oauthplayground/ )

Solutions Collecting From Web of "获取android订阅状态,失败403"

我花了一些时间在这个,但最后的错误消息说:“[…]尚未链接到Google Play开发者控制台”。

我花了好几个小时的时间在Google开发者控制台中查看,但是链接项目的地方位于Google Play开发者控制台中。

只需进入设置 – > API访问,您就可以链接您在Google Developer Console中创build的项目。

这是一个有效的PHP解决scheme来获得订阅状态。 您需要在Google Developer Console中创build一个服务帐户 – >“您的项目” – > API&Auth – > Credential,然后从https://github.com/google/google-api-php-客户

  set_include_path("../src/" . PATH_SEPARATOR . get_include_path()); require_once 'Google/Client.php'; require_once 'Google/Service/AndroidPublisher.php'; $client_id = ''; //Your client id $service_account_name = ''; //Your service account email $key_file_location = ''; //Your p12 file (key.p12) $client = new Google_Client(); $client->setApplicationName(""); //This is the name of the linked application $service = new Google_Service_AndroidPublisher($client); $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/androidpublisher'), $key ); $client->setAssertionCredentials($cred); if($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $apiKey = ""; //Your API key $client->setDeveloperKey($apiKey); $package_name = ""; //Your package name (com.example...) $subscriptionId = ""; //SKU of your subscription item //Token returned to the app after the purchase $token = ""; $service = new Google_Service_AndroidPublisher($client); $results = $service->purchases_subscriptions->get($package_name,$subscriptionId,$token,array()); print_r ($results); //This object has all the data about the subscription echo "expiration: " . $results->expiryTimeMillis; exit; 

我有同样的问题。 似乎authentication在v2 api中已经改变。

您仍然可以使用旧的API端点(v1.1)。 这对我来说可以。

https://www.googleapis.com/androidpublisher/v1.1/applications/{packageName}/inapp/{productId}/purchases/{token}

我使用了Fabrizio Farenga的代码和Google API代码,效果很好。 另外,值得注意的是,您的服务帐户需要访问的权限只是查看财务报告