I am facing error
==================================
Exception: Response has unsuccessful status in
/var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Http/Client.php:44
Stack trace:
#0 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(310):
RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))
#1 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(434):
RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request), Array)
#2 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(212):
RingCentralSDKPlatformPlatform->requestToken('/restapi/oauth/...', Array)
#3 /var/www/html/api/public_html/sendSMS.php(38): RingCentralSDKPlatformPlatform->login(Array)
#4 {main}
Next RingCentralSDKHttpApiException: Unauthorized for this grant type in
/var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Http/Client.php:52
Stack trace:
#0 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(310):
RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))
#1 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(434):
RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request), Array)
#2 /var/www/html/api/public_html/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(212):
RingCentralSDKPlatformPlatform->requestToken('/restapi/oauth/...', Array)
#3 /var/www/html/api/public_html/sendSMS.php(38): RingCentralSDKPlatformPlatform->login(Array)
#4 {main}Unable to authenticate to platform. Check credentials.
==========
My Code
<?php
//Header config
require __DIR__ . '/header.php';
/**Db connect */
require __DIR__ . '/dbConnect.php';
/**Ringcentral vendor config */
require __DIR__ . '/vendor/autoload.php';
//fetch all keys from database
//$query = 'SELECT * FROM public."Settings"';
//$result = pg_query($db, $query);
//while ($row = pg_fetch_assoc($result)) {
$clientId = 'Xis4z9ojiqff8kozXxEFcQ';
$clientSecret = '48TxqwJG...';
$jwtToken = 'eyJraWQiOiI4...';
$fromNumber = '+1704626XXX';
//}
$serverUrl = 'https://platform.ringcentral.com';
//$jsonValue = $_GET 'finalJson'];
//$jsonValue = json_decode($jsonValue);
//receipient number
$receipientNo = '+1480409XXX';
// sms content
$message = 'Hello Sky';
# Instantiate the SDK and get the platform instance
$rcsdk = new RingCentralSDKSDK( $clientId,
$clientSecret,
$serverUrl );
$platform = $rcsdk->platform();
// Authenticate a user using a personal JWT token
try {
$platform->login( ; "jwt" => $jwtToken ] );
send_sms($fromNumber);
} catch (RingCentralSDKHttpApiException $e) {
echo $e;
exit("Unable to authenticate to platform. Check credentials. ");
}
/*
Read phone number(s) that belongs to the authenticated user and detect if a phone number
has the SMS capability
*/
function read_extension_phone_number_detect_sms_feature(){
global $platform;
$endpoint = "/restapi/v1.0/account/~/extension/~/phone-number";
$resp = $platform->get($endpoint);
$jsonObj = $resp->json();
foreach ($resp->json()->records as $record){
foreach ($record->features as $feature){
if ($feature == "SmsSender"){
// If a user has multiple phone numbers, check and decide which number
// to be used for sending SMS message.
return send_sms($record->phoneNumber);
}
}
}
if (count($jsonObj->records) == 0){
exit("This user does not own a phone number!");
}else{
exit("None of this user's phone number(s) has the SMS capability!");
}
}
/*
Send a text message from a user own phone number to a recipient number
*/
function send_sms($FROM_NUMBER){
global $platform, $receipientNo, $message;
try {
$requestBody = array(
'from' => array ('phoneNumber' => $FROM_NUMBER),
'to' => array( array('phoneNumber' => $receipientNo) ),
// To send group messaging, add more (max 10 recipients) 'phoneNumber' object. E.g.
/*
'to' => array(
array('phoneNumber' => $receipientNo),
array('phoneNumber' => 'Recipient-Phone-Number')
),
*/
'text' => $message
);
$endpoint = "/account/~/extension/~/sms";
$resp = $platform->post($endpoint, $requestBody);
$jsonObj = $resp->json();
print("SMS sent. Message id: " . $jsonObj->id . PHP_EOL);
check_message_status($jsonObj->id);
} catch (RingCentralSDKHttpApiException $e) {
exit("Error message: " . $e->message . PHP_EOL);
}
}
/*
Check the sending message status until it's out of the queued status
*/
function check_message_status($messageId){
global $platform;
try {
$endpoint = "/restapi/v1.0/account/~/extension/~/message-store/".$messageId;
$resp = $platform->get($endpoint);
$jsonObj = $resp->json();
print("Message status: " . $jsonObj->messageStatus . PHP_EOL);
if ($jsonObj->messageStatus == "Queued"){
sleep(2);
check_message_status($jsonObj->id);
}
} catch (RingCentralSDKHttpApiException $e) {
exit("Error message: " . $e->message . PHP_EOL);
}
}
?>
===========