gpt4 book ai didi

android - 获取 android 订阅状态​​,失败并返回 403

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:12 27 4
gpt4 key购买 nike

在尝试获取 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."
}
}

网址是: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 Playground ,但没有成功 ( https://developers.google.com/oauthplayground/ )

最佳答案

我在这上面花了一些时间,但最后错误消息说明了一切:“[...] 尚未在 Google Play 开发者控制台中链接”。

我花了几个小时查看 Google Developer Console,但链接项目的地方是在 Google Play Developer Console 中。

只需转到设置 -> Api 访问,您就可以链接您在 Google 开发者控制台中创建的项目。

这是一个用于获取订阅状态的有效 PHP 解决方案。您需要在 Google Developer Console -> 'your project' -> API & Auth -> Credential 中创建一个服务帐户,然后从 https://github.com/google/google-api-php-client 下载 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;

关于android - 获取 android 订阅状态​​,失败并返回 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25054919/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com