Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未发送Google YouTube API刷新令牌_Php_Youtube_Google Api_Youtube Api_Oauth 2.0 - Fatal编程技术网

Php 未发送Google YouTube API刷新令牌

Php 未发送Google YouTube API刷新令牌,php,youtube,google-api,youtube-api,oauth-2.0,Php,Youtube,Google Api,Youtube Api,Oauth 2.0,我正试图基于Google的文档在PHP中使用Google YouTube数据API:。当使用OAuth进行身份验证时,出现了我的问题。我正在使用下面的授权URL,除了重定向uri和应用程序密钥之外,它显然与文档所说的要使用的URL相同 $this->authorizationUrl = 'https://accounts.google.com/o/oauth2/auth?'; $this->authorizationUrl .= 'client_id=' . $this->ap

我正试图基于Google的文档在PHP中使用Google YouTube数据API:。当使用OAuth进行身份验证时,出现了我的问题。我正在使用下面的授权URL,除了重定向uri和应用程序密钥之外,它显然与文档所说的要使用的URL相同

$this->authorizationUrl = 'https://accounts.google.com/o/oauth2/auth?';
$this->authorizationUrl .= 'client_id=' . $this->applicationKey . '&';
$this->authorizationUrl .= 'redirect_uri=' . $this->redirect_uri . '/account.php?action=youtube_oauth&';
$this->authorizationUrl .= 'scope=https://gdata.youtube.com&';
$this->authorizationUrl .= 'response_type=code&';
$this->authorizationUrl .= 'access_type=offline';
然后,正如医生们所说,我要做以下几点:

$curl_options = Array(
            CURLOPT_POSTFIELDS => Array(
                'code' => $code,
                'client_id' => $this->applicationKey,
                'client_secret' => $this->applicationSecret,
                'redirect_uri' => $this->redirect_uri . '/account.php?action=youtube_oauth',
                'grant_type' => 'authorization_code'
            ),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token'
        );
然而,我的回复从来没有像他们的文档所说的那样给我一个刷新令牌。我只得到了其他三个响应项

像这样的一些问题:我说过要使用approval\u prompt=force,但这也不起作用,完全违背了让access\u type=offline的目的


关于为什么我会得到4个回复项目中的3个的有效回复,你有什么想法吗?

你可以试试谷歌oauth2游乐场(https://code.google.com/oauthplayground/)并查看您的参数与它们之间的区别。

来自OAuth2.0文档的部分:

当您的应用程序收到刷新令牌时,它是 存储该刷新令牌以供将来使用很重要。如果你的 应用程序丢失刷新令牌,必须重新提示 在获取另一个刷新令牌之前,请获得用户的同意。如果你需要 要重新提示用户同意,请包括
批准\u提示
参数,并将该值设置为
强制

因此,当您已经授予访问权限时,对
授权\u code
授予类型
的后续请求将不会返回
刷新令牌
,即使在同意页面的查询字符串中将
访问类型
设置为
脱机

如上所述,为了在已经收到一个新的
刷新\u令牌
后获得一个新的刷新\u令牌,您需要通过提示符将您的用户发送回,您可以通过将
批准\u提示符
设置为
强制
来完成此操作

干杯


PS这项更改也是在a中宣布的。

为了让我自己感到困惑的其他人受益,一旦您获得了
刷新令牌
,您就不需要再刷新它,因为您可以反复使用相同的令牌。只有在您丢失或用户撤销您的访问权限时,才需要一个新的。