【问题标题】:How to authorize in Google Play Developer API using PHP如何使用 PHP 在 Google Play Developer API 中进行授权
【发布时间】:2016-01-28 01:20:12
【问题描述】:

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。我不知道下一步该怎么做。

【问题讨论】:

    标签: php rest google-play-developer-api


    【解决方案1】:

    试试看这个: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。

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 2012-02-25
      • 1970-01-01
      • 2018-04-17
      • 2023-03-15
      相关资源
      最近更新 更多