Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RingCentral PHP SDK throwing Uncaught exception InvalidArgumentException on login #29

Closed
numanilyas opened this issue May 21, 2016 · 6 comments

Comments

@numanilyas
Copy link

commented May 21, 2016

I am trying to use RingCentral PHP SDK to send SMS. When I use code from demo then I get error shown in below screenshot. When I use JS SDK with same credentials then I am able to successfully send SMS. Following is my code for php:

use RingCentral\SDK\SDK;
// require_once(__DIR__ . '/vendor/_bootstrap.php');
require(__DIR__ . '/vendor/autoload.php');

$rcsdk = new SDK('appKey', 'appSecret', SDK::SERVER_SANDBOX);
$platform = $rcsdk->platform();

$platform->login('sandbox_no', '', 'password');

Please let me know if I am missing something or I need to install any additional component.
php sdk invalidargumentexception

@anilkumarbp

This comment has been minimized.

Copy link
Contributor

commented May 22, 2016

You would need to include Composer's autoloader ( https://github.com/ringcentral/ringcentral-php#with-composer-recommended ) within your code to:

  • Authenticate
  • Send SMS

Our Demo application within the SDK, uses a _credentials.json file to save details like:

{
    "appKey": "",
    "appSecret": "",
    "server": "https://platform.devtest.ringcentral.com",
    "username": "1xxxxxxxxxx",
    "extension": "",
    "password": "",
    "fromPhoneNumber": "1xxxxxxxxxx",
    "toPhoneNumber": "1xxxxxxxxxx",
    "dateFrom": "YYYY-MM-DD",
    "dateTo": "YYYY-MM-DD"
}

If you do not wish to use the _credentials.json file please take a look at the code below:

<?php

use RingCentral\SDK\SDK;
use RingCentral\SDK\Http\HttpException;
use RingCentral\http\Response;
require_once(__DIR__ . '/vendor/autoload.php');
try {

$rcsdk = new SDK("sandbox appKey", "sandbox appSecret" , SDK::SERVER_SANDBOX , 'Demo', '1.0.0');
$platform = $rcsdk->platform();
$auth = $platform->login("sandbox number", "extensnion_number", "sandbox password");

    // Send SMS
    $apiResponse = $platform->post('/account/~/extension/~/sms', array(
        'from' => array('phoneNumber'=> '1xxxxxxxxxx'),
        'to' => array(
                    array('phoneNumber' => '1xxxxxxxxxx'),
                    ),
        'text' => 'Testing !',  
        ));
    print 'Sent SMS ' . $apiResponse->json()->uri . PHP_EOL;
} catch (Exception $e) {
    print 'The error is : ' . $e->getMessage() . PHP_EOL;
}
@numanilyas

This comment has been minimized.

Copy link
Author

commented May 22, 2016

Hi Anil,

Thanks for taking a look. I have installed using composer and you can see in my code I am including autoload:

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

I have tried your code and I am still getting same error:
php sdk invalid respons string

Regards,
Numan Ilyas

@LingForCC

This comment has been minimized.

Copy link

commented May 22, 2016

Another possible problem could be CURLOPT_SSL_VERIFYPEER is set incorrectly.

Find the php file named ringcentral-php/src/Http/Client.php in sdk. And add following code at line 73

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

This is to disable SSL certification verification for cURL library before sending the request.

If it is the problem, the reason is that the environment your demo code running on is not associated with a certificate. You could ref this StackOverflow Question for more info.

@numanilyas

This comment has been minimized.

Copy link
Author

commented May 22, 2016

Thanks Ling. Setting CURLOPT_SSL_VERIFYPEER to false fixed the issue.

I have also tried the suggestion mentioned in StackOverflow answer and that also works for me.

Regards,
Numan Ilyas

@numanilyas numanilyas closed this May 22, 2016

@grokify

This comment has been minimized.

Copy link
Member

commented May 22, 2016

For posterity, the accepted answer in the Stack Overflow question suggests downloading and installing the trusted CA certificate file from:

Then you can set the path to the PEM file in the SDK code or your php.ini file:

(1) cURL code

This option would require modifying the SDK the Cient.php code as mentioned by @LingForCC. 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) php.ini file

This option can be used with the PHP SDK as is.

curl.cainfo=/path/to/cacert.pem

If using the php.ini file works, that's great. If there's a reason to need to pass in the path file to the SDK, let us know via this issue or a pull request.

@ghost

This comment has been minimized.

Copy link

commented Sep 5, 2017

RingCentral\SDK\SDK constructor accepts GuzzleHttp\Client as the last argument. The following will work fine for testing and such.

$guzzle = new \GuzzleHttp\Client(['verify' => false]);
$sdk = new \RingCentral\SDK\SDK($key, $secret, $server, 'demo', '1.0.0', $guzzle);
$platform = $sdk->platform();
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.