Exchange Code to Token Failed

  • 1
  • Problem
  • Updated 9 months ago
This is my Code for getting token.
$code=$_REQUEST['code'];
$APPKEY="u8hj81KeQ9uQDyA1PBTTgw";
$req='https://platform.devtest.ringcentral.com/restapi/oauth/token';
$post = array (
'grant_type' => 'authorization_code',
'code' => $code ,
'redirect_uri' => 'http://localhost/token.php');

$ch = curl_init($req);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiKey = base64_encode($APPKEY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $apiKey,
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'));

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


$response = curl_exec($ch);
curl_close($ch);
$r=json_decode($response, true);





And the Response is 
array (size=3)
  'error' => string 'invalid_client' (length=14)
  'error_description' => string 'Invalid client: ' (length=16)
  'errors' => 
    array (size=1)
      0 => 
        array (size=3)
          'errorCode' => string 'OAU-153' (length=7) 
          'message' => string 'Invalid client: ' (length=16)



I am using the same Client ID for getting authorized Code.
Please Help me what is Wrong.
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
You forget AppSecret
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Now look this is correct ?
<?php


$code=$_REQUEST['code'];
$APPKEY="u8hj81KeQ9uQDyA1PBTTgw";
$req='https://platform.devtest.ringcentral.com/restapi/oauth/token';
$post = array (
'grant_type' => 'authorization_code',
'code' => $code ,
'client_secret', => 'l_IDw9I3QgW1zirl_PlqoQmLJM4Df2TCOBeN5FcF8_lQ',
'redirect_uri' => 'http://localhost/token.php&client_id=u8hj81KeQ9uQDyA1PBTTgw');

$ch = curl_init($req);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiKey = base64_encode($APPKEY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $apiKey,
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'));

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


$response = curl_exec($ch);
curl_close($ch);
$r=json_decode($response, true);
var_dump($r);
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
Do you get the correct result? If no, what's the error message?
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
i am getting this response ..

array (size=3)
  'error' => string 'invalid_client' (length=14)
  'error_description' => string 'Invalid client: ' (length=16)
  'errors' => 
    array (size=1)
      0 => 
        array (size=3)
          'errorCode' => string 'OAU-153' (length=7)
          'message' => string 'Invalid client: ' (length=16)
          'parameters' =>  
array (size=1) 
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
(Edited)
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
When i use the official SDK i am getting grant issue because i am trying to make a web application.
I am totally confuse what to do ?
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
If you have problem using the official SDK, you should post the problem here instead of writing your own solution. Because your own solution will have that grant issue too.
(Edited)
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
After a lot of struggle i am trying to write my own code, because ringcentral developer email is not replying to my problem .
Please help me .
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
Just post the problem in the devcommunity and you will get the help as soon as we see it. Probably much faster than the email help. Here is the preferred place for us to help developers.

But first of all, I need to know what kind of problem are you having with the official SDK.
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Auth exception: Refresh token has expired Exception: Unauthorized for this grant type SDK HTTP Error at https://platform.devtest.ringcentral.com/restapi/oauth/token Response text: { "error" : "unauthorized_client", "error_description" : "Unauthorized for this grant type", "errors" : [ { "errorCode" : "OAU-251", "message" : "Unauthorized for this grant type" } ] }
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
(Edited)
Photo of Etam Singh

Etam Singh

  • 160 Points 100 badge 2x thumb
Refresh Token using sdk:

 SDK sdk = new SDK( "ktx884**********-TL-O3Q",
               "RNLRm1zYR**************4JxrC5CTjKpWF3KwRlFPg",
               "https://platform.devtest.ringcentral.com";,
               " ",
               ""); 

Dictionary<string, string> obj = new Dictionary<string, string>();

  obj.Add("refresh_token", CurrentUser.RCRefreshToken);
  obj.Add("grant_type", "refresh_token");
                   
 var request = new Request("/restapi/oauth/token/",obj);                    
  var responseToken = sdk.Platform.Post(request);


Getting Error:Access Expired

Can u please tell me.how can I refresh  access token using Refresh Token Flow
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
The sample code you post is not PHP. Could you please provide more information?  If you tell me the programming language, I might be able to provide with you some sample code.
Photo of sahiba singh

sahiba singh

  • 90 Points 75 badge 2x thumb
The above language is c#
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,462 Points 5k badge 2x thumb
A new thread is preferred. Because this one is old and it's about PHP.  I answered this question in another thread.