如何使用 PHP 在 Google Play Developer API 中授权
How to authorize in Google Play Developer API using PHP
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
但是returns:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
它需要我先授权,这很难理解文档。
I am using Laravel 4.2.
With Amazon ec2 Linux
我的目标是在我的应用程序中获取订阅用户的状态,如果用户已付费,过期等
我已经这样做了:https://developers.google.com/android-publisher/authorization
创建了我的项目,打开 Google Play Android Developer API 并创建客户端 ID。我不知道接下来要做什么。
尝试并遵循以下步骤: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 确认登录,它将被重定向到您的 url:https://website.com/callback
其中 link 使用 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.
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
但是returns:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
它需要我先授权,这很难理解文档。
I am using Laravel 4.2.
With Amazon ec2 Linux
我的目标是在我的应用程序中获取订阅用户的状态,如果用户已付费,过期等
我已经这样做了:https://developers.google.com/android-publisher/authorization
创建了我的项目,打开 Google Play Android Developer API 并创建客户端 ID。我不知道接下来要做什么。
尝试并遵循以下步骤: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 确认登录,它将被重定向到您的 url:https://website.com/callback
其中 link 使用 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.