jos*_*lat 7 php youtube google-api youtube-api oauth-2.0
我正在尝试使用基于Google文档的Google YouTube数据API和PHP:https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Refreshing_a_Token.在使用OAuth进行身份验证时,我的问题就出现了.我正在使用以下授权URL,该URL与文档所说的相同,除了我的重定向uri和应用程序密钥,显然.
$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';
Run Code Online (Sandbox Code Playgroud)
然后,正如文档所说,我提出以下内容:
$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'
);
Run Code Online (Sandbox Code Playgroud)
但是,我的回复从来没有像我们的文档所说的那样给我一个refresh_token.我只得到其他三个响应项.
像这样的一些问题:获取刷新令牌google api已经说过使用approval_prompt = force,但这也不起作用,完全违背了access_type = offline的目的.
有关为什么我会得到4个响应项中的3个的有效回复的任何想法?
bos*_*ter 29
从OAuth2.0文档的离线访问部分:
当您的应用程序收到刷新令牌时,存储该刷新令牌以供将来使用非常重要.如果您的应用程序丢失了刷新令牌,则必须在获得另一个刷新令牌之前重新提示用户同意.如果需要重新提示用户同意,请
approval_prompt
在授权代码请求中包含该参数,并将值设置为force
.
因此,当您已经授予访问权限时,即使在同意页面的查询字符串中设置了后续请求grant_type
,authorization_code
也不会返回.refresh_token
access_type
offline
由于在报价如上所述,为了获得一个新的 refresh_token
已经接收到一个后,您将需要通过提示,您可以通过设置做你的用户发回approval_prompt
给force
.
干杯,
PS此更改也在博客文章中公布.
您可以尝试 google oauth2 Playground (https://code.google.com/oauthplayground/) 并查看您的参数和那里的参数之间有什么区别。
归档时间: |
|
查看次数: |
5634 次 |
最近记录: |