【发布时间】:2012-04-10 02:54:39
【问题描述】:
我正在尝试根据此处的 Google 文档将 Google YouTube Data API 与 PHP 一起使用:https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Refreshing_a_Token。使用 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 如下:
$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'
);
但是,我的回复从来没有像他们的文档所说的那样给我一个 refresh_token。我刚刚得到其他三个响应项。
像这样的一些问题:Get refresh token google api 说要使用approval_prompt=force,但这也不起作用,完全违背了让access_type=offline 的目的。
关于为什么我会在 4 个响应项中的 3 个得到有效响应的任何想法?
【问题讨论】:
标签: php youtube google-api youtube-api oauth-2.0