3
votes

Google Play Developer API Documentation Reference: https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get

I am using the Purchases.subscriptions: get Method

I have call the request using GetPostMan and Unirest PHP:

GET https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/subscriptions/subscriptionId/tokens/token

But returns:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "required",
        "message": "Login Required",
        "locationType": "header",
        "location": "Authorization"
      }
    ],
    "code": 401,
    "message": "Login Required"
  }
}

It requires me to Authorize first which is difficult to understand the documentation.

I am using Laravel 4.2.

With Amazon ec2 Linux

My goal is to get the status of subscribe users in my App, if the user is paid, expired, etc.

I have already done this: https://developers.google.com/android-publisher/authorization

Created my project, Turn the Google Play Android Developer API on and Create client ID. I don't know what to do next.

1

1 Answers

0
votes

Try and follow this: https://developers.google.com/android-publisher/authorization

<?php 
        $google        = "https://accounts.google.com/o/oauth2/auth";
        $scope         = "https://www.googleapis.com/auth/androidpublisher";
        $response_type = "code";
        $access_type   = "offline";
        $redirect_uri  = "https://website.com/callback";
        $client_id     = $client_id;
        $url            = $google."?scope=".$scope."&response_type=".$response_type."&access_type=".$access_type."&redirect_uri=".$redirect_uri."&client_id=".$client_id;
?>

Once you login through Google confirmation it will be redirected to your url: https://website.com/callback

in that link put this code using Unirest:

<?php 
        $headers = array();
        $body    = array(  
                    'grant_type'    => 'authorization_code',
                    'code'          => $code."#",
                    'client_id'     => $client_id,
                    'client_secret' => $client_secret,
                    'redirect_uri'  => "https://website.com/callback",
        );

        $response = Unirest\Request::post("https://accounts.google.com/o/oauth2/token", $headers, $body);

        var_dump($response->body);

?>

Note that the $code is from the $url.