gpt4 book ai didi

php - 如何使用 PHP 在 Google Play Developer API 中进行授权

转载 作者:行者123 更新时间:2023-12-04 20:11:46 24 4
gpt4 key购买 nike

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"
}
}

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

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 确认登录,它将被重定向到您的网址: 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。

关于php - 如何使用 PHP 在 Google Play Developer API 中进行授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com