4

Google Play 开发者 API 文档参考: https ://developers.google.com/android-publisher/api-ref/purchases/subscriptions/get

我正在使用Purchases.subscriptions: get方法

我已经使用 GetPostMan 和 Unirest PHP 调用了请求:

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

但返回:

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

它需要我先授权,这很难理解文档。

我正在使用 Laravel 4.2。

使用 Amazon ec2 Linux

我的目标是在我的应用程序中获取订阅用户的状态,如果用户已付费、过期等。

我已经这样做了:https ://developers.google.com/android-publisher/authorization

创建了我的项目,打开 Google Play Android Developer API 并创建客户端 ID。我不知道下一步该做什么。

4

1 回答 1

0

尝试并遵循这个: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;
?>

一旦您通过 Google 确认登录,它将被重定向到您的网址:https ://website.com/callback

在该链接中使用 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);

?>

请注意,$code 来自 $url。

于 2016-02-02T05:52:39.447 回答