无法从Google API OAuth2刷新令牌

kn3l

这是我的PHP脚本 RefreshToken.php

<?php
$url = 'https://accounts.google.com/o/oauth2/token';
$post_data = array(
                    'code'          =>   'xxxxxxxx',
                    'client_id'     =>   'xxxxxxxxxxx',
                    'client_secret' =>   'xxxxxxxxxxxxx',
                    'redirect_uri'  =>   'http://localhost/googleapi/AuthenticationCode.php',
                    'grant_type'    =>   'authorization_code',
                    );
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
$token = json_decode($result);

echo $token->refresh_token . "\n";
?>

运行PHP CLI

php -q RefreshToken.php

PHP注意:第20行的/var/www/googleapi/RefreshToken.php中未定义的属性:stdClass :: $ refresh_token

雷尔·古格尔敏·库尼亚(Rael Gugelmin Cunha)

refresh_token默认情况下不会在谷歌的OAuth2返回。

请求授权码需要一个额外的参数(access_type):然后刷新令牌将与access_token一起返回。

其他异常行为:refresh_token仅对用户返回一次。如果由于某种原因refresh_token丢失了该用户,则该用户将需要打开Google帐户安全设置页面并放弃对您的应用程序的访问权限。但这还不够:您的应用将需要传递更多一个参数(approval_prompt等于true),以表明我们正在强制要求新的参数refresh_token

更多信息:https : //developers.google.com/accounts/docs/OAuth2WebServer#offline

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot-Google OAuth2,将刷新令牌存储在数据库中

如何在Google API中使用oauth2和刷新令牌?

Golang Google云端硬盘Oauth2不返回刷新令牌

Spring OAuth2刷新令牌-无法将访问令牌转换为JSON

Google Oauth2:刷新OAuth2令牌时出错,消息:'{“ error”:“ invalid_grant”}'

Google API OAuth2-从授权令牌获取刷新令牌

刷新OAuth2令牌@ Google_CalendarServices(php)时出错

Google oauth2刷新令牌何时失效?

如何使用Javascript从Google Api检索服务帐户OAuth2令牌?

Google OAuth2即使使用access_type ='offline'也不会发出刷新令牌吗?

如何获取Google oauth2刷新令牌?

Google OAuth2 API按子域的单独令牌

如何刷新OAuth2令牌?我需要等待令牌到期吗?(Patreon API)

您如何使用Google API getRequestHeaders()获取OAuth2访问令牌?

Google Adwords API PHP-删除当前访问令牌的Oauth2访问权限

在刷新/使用React应用中的Google OAuth2刷新令牌后保持用户登录

Passport.js / Google OAuth2策略-如何在登录时使用令牌访问API

带有刷新令牌的春季Google OAuth2

为什么Google OAuth Api会刷新令牌?

如何使用Firebase函数刷新Google oauth2上的令牌?

无法获取Google驱动器的刷新令牌(Google API v2)

Google OAuth2 API

是否可以使用Google oauth2检索刷新令牌

Google API-来自Oauth2的令牌请求返回空令牌

无法使用Google OAuth 2获取刷新令牌

Google API刷新令牌

从 API 获取访问令牌 (oauth2)

使用邮递员使用 Google API 获取 OAuth2 令牌

如何讓 Google 的 OAuth API 自動刷新令牌?