Fatal error: Uncaught exception 'Exception' with message 'Response has unsuccessful status' and "Unauthorized for this grant type"

  • 1
  • Question
  • Updated 2 years ago
  • (Edited)
Facing this fatal error Response has unsuccessful status

use RingCentral\SDK\Http\HttpException;
use RingCentral\Http\Response;
use RingCentral\SDK\SDK;

require_once(__DIR__ . '/vendor/autoload.php');

$rcsdk = new SDK('******', '*****', 'https://platform.devtest.ringcentral.com', 'Demo', '1.0.0');
$platform = $rcsdk->platform();
$auth = $platform->login('+12679304066', '101', '*******');
// Load something nonexistent
echo 'login response:' . $auth->text(). PHP_EOL;

installed via composer curl is enabled and also added i php.ini
curl.cainfo = "E:/wamp/cacert.pem" after downloading pem file.
Photo of Hassan Shahzad

Hassan Shahzad

  • 140 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
Hi Hassan,

If you are using custom SSL Certificates you could adopt the following methods to set the path to the PEM file :

1.) Within the SDK

This option would require modifying the SDK the Cient.php code. When using this approach, ideally the path parameter could be passed into the SDK.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");    

 2.)  using the php.ini file
You would have to add this to the php.ini file :
curl.cainfo=/path/to/cacert.pem
For more detailed information Refer to this in our Github-PHP-SDK-Issue

Could you verify if the certificate is valid if you are using the option 2 specified above
(Edited)
Photo of Hassan Shahzad

Hassan Shahzad

  • 140 Points 100 badge 2x thumb
Ak,
I had already go through this link and resolve this error by second method you specify, after that i am facing this error attached in my issue.
I follow your first step Within the SDK but even then this issue exists.
please help
Photo of AK

AK, Official Rep

  • 4,402 Points 4k badge 2x thumb
Hi Hassan,

The reason you are getting that error is because your application is of type "Public" and we make sure that all the RingCentral Applications of type Public implement the  Authorization Code Flow mandatorily.

Kindly take a look at our demo in PHP here :
https://github.com/grokify/ringcentral-demos-oauth/tree/master/php

For further information on Authorization Flow, please refer to our documentation here :
https://developer.ringcentral.com/api-docs/latest/index.html#!#AuthorizationCodeFlow

Let us know if you are able to get it working. Thanks.