oauth-GoogleAPI不支持的授权类型

lymnna71  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(291)

我已经在检查具有相同错误的其他线程,但仍然无法修复它。
下面是我的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: "
}

我希望有人能帮忙。任何提示、链接或代码片段都可以!非常感谢。

yiytaume

yiytaume1#

POST https://accounts.google.com/o/oauth2/token
client_id={ClientId}&client_secret={ClientSecret}&refresh_token=[TOKEN]&grant_type=refresh_token

该调用是一个http post调用,数据是一个字符串,选项之间用&符号分隔。
您正在以数组形式发送post数据。

相关问题