【问题标题】:Why do I keep getting unsupported_grant_type when using oAuth2 and curl?为什么我在使用 oAuth2 和 curl 时不断收到 unsupported_grant_type?
【发布时间】:2017-09-04 03:25:04
【问题描述】:

我正在尝试使用 uber rush api 验证我的身份,但我不断收到 unsupported_grant_type 错误消息。我不确定我在这里做错了什么。任何帮助将非常感激。下面是我正在使用的代码

下面是命令行请求的样子:

curl -F "client_secret=<CLIENT_SECRET>" \
    -F "client_id=<CLIENT_ID>" \
    -F "grant_type=client_credentials" \
    -F "scope=delivery" \
    https://login.uber.com/oauth/v2/token

这是我用 PHP 编写的方法

$cl = curl_init("https://login.uber.com/oauth/v2/token");


curl_setopt($cl,CURLOPT_POST,["client_secret"=>"********"]);
curl_setopt($cl,CURLOPT_POST,["client_id"=>"**********"]);
curl_setopt($cl,CURLOPT_POST,["grant_type"=>"client_credentials"]);
curl_setopt($cl,CURLOPT_POST,["scope"=>"delivery"]);
$content = curl_exec($cl);
curl_close($cl);


var_dump($content);

【问题讨论】:

  • 您使用了错误的选项来设置 POST 参数。在文档中搜索CURLOPT_POST,此处为:php.net/manual/en/function.curl-setopt.php。您会看到它需要一个布尔值来指示请求是否应使用 POST 方法。

标签: php curl oauth-2.0 uber-api


【解决方案1】:

这不是将 POST 数据添加到 cURL 的方法。有PHP documentation 告诉您这些选项的实际含义。试试这个:

<?php
$postdata = [
    "client_secret"=>"xxx",
    "client_id"=>"xxx",
    "grant_type"=>"client_credentials",
    "scope"=>"delivery",
];
$cl = curl_init("https://login.uber.com/oauth/v2/token");

curl_setopt_array($cl, [
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => $postdata,
    CURLOPT_RETURNTRANSFER => true
]);
$content = curl_exec($cl);
curl_close($cl);
var_dump($content);

【讨论】:

  • 好的,明白了。我对 cURL 不熟悉,但感谢您的解释!
【解决方案2】:

如果上面的答案不起作用,这个答案也非常有用:Curl Grant_Type not found FIXED

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    相关资源
    最近更新 更多