neo*_*bie 10 android google-api subscription in-app
在尝试获取Android应用内订阅状态(有效期限)时,我收到以下错误消息:
{
"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."
}
}
Run Code Online (Sandbox Code Playgroud)
该网址为:https://www.googleapis.com/androidpublisher/v2/applications/[packageName]/inapp/ [productId]/purchases/[purchase_token]?access_token=[access_token]
它说项目ID没有链接.我做了以下事情:
Run Code Online (Sandbox Code Playgroud)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/)
Fab*_*nga 13
我花了一些时间在这上面,但最后错误信息显示所有:"[...]未在Google Play开发者控制台中链接".
我花了好几个小时查看Google Developer Console,但链接项目的位置在Google Play Developer控制台中.
只需转到设置 - > Api访问,您就可以链接您在Google Developer Console中创建的项目.
这是一个有效的PHP解决方案,用于获取订阅状态.您需要在Google Developer Console中创建一个服务帐户 - >"您的项目" - > API&Auth - > Credential并从https://github.com/google/google-api-php-下载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;
Run Code Online (Sandbox Code Playgroud)
我有同样的问题。v2 api 中的身份验证似乎已更改。
您仍然可以使用旧的 api 端点 (v1.1)。这对我来说可以。
https://www.googleapis.com/androidpublisher/v1.1/applications/{packageName}/inapp/{productId}/purchases/{token}
归档时间: |
|
查看次数: |
10519 次 |
最近记录: |