簡體   English   中英

"獲取android訂閱狀態,403失敗"

[英]Get android subscription status, failed with 403

在嘗試獲取 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."
 }
}

我花了一些時間在這上面,但最后錯誤信息顯示所有:“[...]未在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;

我有同樣的問題。 似乎v2 api中的身份驗證已更改。

您仍然可以使用舊的api端點(v1.1)。 這對我來說可以。

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

我使用了Fabrizio Farenga的代碼和Google API代碼,效果很好。 此外,值得注意的是,您的服務帳戶訪問此權限所需的權限只是查看財務報告

它是2019年,這個問題仍然存在。 但是,我在某個地方找到了另一個答案,有人說你在設置這個應用程序之后必須在你的帳戶中創建一個新產品......而實際上對我有用。

在@FabrizioFarenga 回答的幫助下,我創建了Google API PHP Client<\/code>最新更新的這段代碼

https:\/\/github.com\/google\/google-api-php-client<\/a>版本 v2.10


        $oauth_credentials = Storage::path('path/to/secret.json');

        $subscriptionId = "";
        $packageName = "";
        $purchaseToken = "";


        $client = new \Google\Client();
        $client->setAuthConfig($oauth_credentials);
        $client->addScope("https://www.googleapis.com/auth/androidpublisher");

        if ($client->isAccessTokenExpired()) {
            $client->fetchAccessTokenWithAssertion();
        }

        if ($client->getAccessToken()) {
            $service = new \Google\Service\AndroidPublisher($client);
            $results = $service->purchases_subscriptions->get($packageName, $subscriptionId, $purchaseToken, []);
            return $results;
        }

        die('die---');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM