【问题标题】:OAuth - Google API unsupported_grant_typeOAuth - Google API unsupported_grant_type
【发布时间】:2021-10-02 04:23:34
【问题描述】:

我已经在检查其他线程有同样的错误,但仍然无法修复它。

这是我的 PHP 代码:

$data = [
        "client_id" => "id-here",
        "client_secret" => "secret-here",
        "refresh_token" => "refresh-token-here",
        "grant_type" => "refresh_token"
    ];
    $ch = curl_init( 'https://www.googleapis.com/oauth2/v4/token' );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded'));
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

    $result = curl_exec($ch);
    curl_close($ch);

    dd($result);

如您所见,我确实包含了“application/x-www-form-urlencoded”,但我仍然收到回复:

{
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: "
}

我希望有人能够提供帮助。 任何提示、链接或代码-sn-ps 都可以! 谢谢!

【问题讨论】:

  • 你为什么不使用google api php客户端库?
  • 我不想包含我不需要的整个 PHP 客户端库,只是在最后发送一个获取请求。因此。但我认为无论如何我都需要以某种方式获取该 OAuth 访问令牌。

标签: php curl oauth google-api google-oauth


【解决方案1】:
POST https://accounts.google.com/o/oauth2/token
client_id={ClientId}&client_secret={ClientSecret}&refresh_token=[TOKEN]&grant_type=refresh_token

调用是一个 http POST 调用,数据是单个字符串,选项由 & 符号分隔。

您将发布数据作为数组发送。

【讨论】:

猜你喜欢
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 2020-06-26
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
  • 2018-04-25
  • 2017-12-01
相关资源
最近更新 更多