【问题标题】:Google authentication from PHP来自 PHP 的 Google 身份验证
【发布时间】:2012-06-06 14:48:43
【问题描述】:

我知道 SO 中有很多类似的问题,但我尝试了这些解决方案几个小时,但它们对我不起作用。我总是收到{ "error" : "unauthorized_client" }"。我想以编程方式刷新我的访问令牌以使用 Youtube API。我已经获得了一个refreshtoken。

这是我想出的:

$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_secret' => '<mysecret>',
'grant_type' => 'refresh_token',
'refresh_token' => '<my_refresh_token>',
'client_id' => '<my_client_id>.apps.googleusercontent.com',
'redirect_url'=>'<my_redirect_uri>'
));
curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
echo var_dump(curl_exec($ch));

这有什么问题?

【问题讨论】:

标签: php youtube refresh token


【解决方案1】:

您指定的 URL 和查询参数对我来说很合适。如果您提供的用于生成新令牌的 client_id 与提供的用于获取 refresh_token 的 client_id 不同,似乎会出现此错误。

可能发生的一件事是,如果您使用 Google 的 OAuth 操场生成了 access_token 和 refresh_token,然后尝试使用该 refresh_token 生成新的令牌 - 这将不起作用。 Google OAuth 游乐场使用不同的 client_id 来发出该请求,这肯定会导致您记录的“unauthorized_client”错误。

Temboo 为 Google 提供了一个非常简洁且易于使用的 OAuth 库。你可以在这里查看:https://www.temboo.com/library/Library/Google/OAuth/

(完全披露:我在 Temboo 工作)

【讨论】:

    猜你喜欢
    • 2017-09-14
    • 2020-07-09
    • 2017-08-17
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多