在试图让机器人在应用程序内订阅状态(与到期日),我收到以下错误信息:
{
错误: {
错误:
{
域:androidpublisher
原因:projectNotLinked
信息:用来调用谷歌Play开发者API项目ID并没有在谷歌Play开发者控制台被联系在一起。
}
]
code:403,
信息:用来调用谷歌Play开发者API项目ID并没有在谷歌Play开发者控制台被联系在一起。
}
}
网址:https://www.googleapis.com/androidpublisher/v2/applications/[packageName]/inapp/[productId]/purchases/[purchase_token]?access_token=[access_token]
报告说,该项目的ID不挂。我也做了以下内容:
1。建立在谷歌开发者控制台项目。
2.打开谷歌Android发布的API。
3.链接中提到的API访问页面的项目ID(https://developers.google.com/android-publisher/getting_started)
4.填写的packageName ID,产品(从应用程序中购买),purchase_token(从Android应用程序)
不知道为什么错误消息如上所示。我曾尝试与OAuth2操场,没有运气(https://developers.google.com/oauthplayground/)
解决方案我花了一些时间在这一点,但在最后的错误消息说,所有: [...]一直没有联系在谷歌Play开发者控制台。
我花了几个小时看在谷歌开发者控制台,但如果链接该项目的位置是在谷歌播放开发控制台。
只要到设置 - > API访问,您将能够链接你在谷歌开发者创建的项目控制台
。下面是一个工作的PHP解决方案,以获得预订状态。你需要在谷歌开发者控制台创建一个服务帐号 - >项目 - > API和放大器;验证 - >凭据和从 https://github.com/google下载谷歌API的PHP客户端/谷歌-API的PHP客户端
set_include_path(../的src /PATH_SEPARATOR get_include_path());
require_once'谷歌/ Client.php;
require_once'谷歌/服务/ AndroidPublisher.php;
$ CLIENT_ID =''; //您的客户端ID
$ service_account_name =''; //您的服务帐户的电子邮件
$ key_file_location =''; //您的P12文件(key.p12)
$客户端=新Google_Client();
$客户 - > setApplicationName(); //这是链接的应用程序的名称
$服务=新Google_Service_AndroidPublisher($客户端);
$键=的file_get_contents($ key_file_location);
$ CRED =新Google_Auth_AssertionCredentials(
$ service_account_name,
阵列('https://www.googleapis.com/auth/androidpublisher'),
$关键
);
$客户 - > setAssertionCredentials($ CRED);
如果($客户端 - > getAuth() - > isAccessTokenExpired()){
$客户 - > getAuth() - > refreshTokenWithAssertion($ CRED);
}
$ apiKey =; //你的API密钥
$客户 - > setDeveloperKey($ apiKey);
$程序包=; //你的包名(com.example ...)
$ subscriptionId =;订阅项目// SKU
//令牌在购买后返回到应用程序
$令牌=;
$服务=新Google_Service_AndroidPublisher($客户端);
$结果= $服务 - > purchases_subscriptions->获得($程序包,$ subscriptionId,$令牌,数组());
的print_r($结果); //这个对象有所有关于认购数据
回声过期。 $结果> expiryTimeMillis;
出口;
While trying to get android in-app subscription status (with expiry date), I get the following error message:
{
"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."
}
}
The URL is: https://www.googleapis.com/androidpublisher/v2/applications/[packageName]/inapp/[productId]/purchases/[purchase_token]?access_token=[access_token]
It says the project id is not linked. I have done the following:
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)
Not sure why the error message appear as above. I have tried with the OAuth2 playground with no luck (https://developers.google.com/oauthplayground/)
解决方案I spent some time on this but at the end the error message says all: "[...] has not been linked in the Google Play Developer Console".
I spent hours looking in the Google Developer Console, but the place where to link the project is in the Google Play Developer console.
Just go to Settings -> Api Access and you'll be able to link the project you created in the Google Developer Console.
Here is a working PHP solution to get the subscription status. You need to create a service account in the Google Developer Console -> 'your project' -> API & Auth -> Credential and download the Google API PHP Client from https://github.com/google/google-api-php-client
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;