1

I am trying to authenticate my self with uber rush api, and I keep getting an unsupported_grant_type error message. I am not sure what am I doing wrong here. Any help would be really appreciated. Below is the code I am using

Here is what the command line request looks like:

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

Here is how I wrote it in 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);
miken32
  • 42,008
  • 16
  • 111
  • 154
json2030
  • 13
  • 3
  • You're using the wrong option to set POST params. Search for `CURLOPT_POST` in the docs, here: http://php.net/manual/en/function.curl-setopt.php. You'll see it expects a boolean to indicate if the request should use `POST` method. – Gustavo Straube Apr 09 '17 at 00:51

2 Answers2

2

This is not how to add POST data to cURL. There is PHP documentation to tell you what these options actually mean. Try this instead:

<?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);
miken32
  • 42,008
  • 16
  • 111
  • 154
0

This answer is also very useful if the above answer doesn't work: Curl Grant_Type not found FIXED.

karel
  • 5,489
  • 46
  • 45
  • 50
Mr Talha
  • 705
  • 7
  • 13