Skip to main content

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.

You forget AppSecret
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);

Why don't you use the official SDK instead? https://github.com/ringcentral/ringcentral-php

If you want to write your own, please reference https://github.com/ringcentral/ringcentral-php/blob/ac9984a8ae2e41239dfe84ae4f698f8a16b22417/src/Pla...  and https://github.com/ringcentral/ringcentral-php/blob/ac9984a8ae2e41239dfe84ae4f698f8a16b22417/src/Pla...
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 ?

Reply