getting this error using php curl for auth/token

  • 1
  • Problem
  • Updated 3 months ago
{
  "error" : "unauthorized_client",
  "error_description" : "Unauthorized for this grant type",
  "errors" : [ {
    "errorCode" : "OAU-251",
    "message" : "Unauthorized for this grant type"
  } ] 
}






here is my code below:- 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.devtest.ringcentral.com/restapi/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+12048184079&password=Reset321$$&extension=101&grant_type=password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "1RjNgM-LTR2REFuE-ggrHA" . ":" . "524fjcIjTbiVR9CPclIZHQwXDDEd8vSayHvx_FdfegzA");

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

echo '<pre>'; print_r($result); die;

if (curl_errno($ch)) {
   echo 'Error:' . curl_error($ch);
}

curl_close ($ch);




Photo of Andrew Auger

Andrew Auger

  • 102 Points 100 badge 2x thumb

Posted 3 months ago

  • 1
Photo of Igor Bebin

Igor Bebin, Official Rep

  • 840 Points 500 badge 2x thumb
Hi Andrew,

The following grant types are available for your application: 
* Authorization Code
* Refresh Access Token

Please find instructions on how to use these flows:
https://developers.ringcentral.com/api-reference#OAuth-2-0
https://ringcentral-api-docs.readthedocs.io/en/latest/oauth/#authorization-flows

Thanks,
Igor
Photo of Andrew Auger

Andrew Auger

  • 102 Points 100 badge 2x thumb
can you correct my code or give me the exact code according to my php curl for this error

(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,026 Points 5k badge 2x thumb
If you want to use password flow, you need to create a new app which supports password flow.