Google Play Developer 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。
使用亚马逊ec2 Linux
我的目标是在我的应用中获取订阅用户的状态,如果用户已付款,已过期等
我已经这样做了:https://developers.google.com/android-publisher/authorization
创建我的项目,打开Google Play Android Developer API并创建客户端ID。我不知道接下来该做什么。
答案 0 :(得分: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。