RingCentral API Login返回无效的响应字符串

时间:2016-07-20 16:27:48

标签: oauth-2.0 ringcentral

我创建了一个Server-only (No UI)私有应用,具有读取呼叫日志权限,并且在发出登录时出现以下错误:

Exception: Invalid response string SDK HTTP Error at https:///platform.devtest.ringcentral.com/restapi/oauth/token Response text: Previous: Invalid response string #0 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(214): RingCentral\SDK\Http\Client->send(Object(RingCentral\Psr7\Request)) \#1 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(301): RingCentral\SDK\Platform\Platform->sendRequest(Object(RingCentral\Psr7\Request), Array) #2 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(123): RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array) #3 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/demo/callRecording.php(25): RingCentral\SDK\Platform\Platform->login('+15188315198', 101, 'xxxxxxxxxxxx', true) #4 {main}

我错过了什么?为什么我会收到此错误? 以下是代码:

require_once('_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = array(
    'username'     => '+15188315198',       // your RingCentral account phone number
    'extension'    => 101,              // or number
    'password'     => 'xxxxxxxxxxxx',
    'appKey'       => 'xxxxxxxxxxxxxxx',
    'appSecret'    => 'xxxxxxxxxxx',
    'server'       => 'https:platform.devtest.ringcentral.com',
    'dateFrom' => '1/1/2016'
); 

$rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();

$platform->login($credentials['username'], $credentials['extension'], $credentials['password'], true);

4 个答案:

答案 0 :(得分:0)

如果您使用Composer安装了我们的PHP SDK,您能否确认一下?

如果有,您能否确认是否遵循以下步骤:

1。)使用Composer安装RingCentral PHP SDK

https://github.com/ringcentral/ringcentral-php#with-composer-recommended 

2。)您需要在PHP脚本中要求使用Composer的AutoLoader。

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

让我们说文件夹结构如下所示:

  

您的申请(申请名称)
      -vendor(PHP SDK whihc使用Composer安装)
      -index.php(应用程序的PHP脚本)

请包含" AutoLoader"在应用程序内的index.php脚本中。

下面是示例代码的样子:

<?php 

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

use RingCentral\SDK\SDK; 

// Create SDK instance 
$rcsdk = new SDK("appKey", "appSecret" , "https://platform.devetst.ringcentral.com", 'Demo', '1.0.0'); 

// Create Platform Singleton Instance 
$platform = $rcsdk->platform(); 

// Login 
$auth = $platform->login("Username", "extension", "password"); 

// Respsone 
print 'Login Success' . $auth->text() . PHP_EOL; 

答案 1 :(得分:0)

  1. 是我使用Composer安装了RingCentral PHP SDK
  2. 我替换了require_once(&#39; _bootstrap.php&#39;); with require_once(&#34; vendor / autoload.php&#34;);虽然这是演示使用的内容 我仍然得到错误。
  3. 我尝试了你包含的简单登录示例,我得到了同样的错误
  4. 致命错误:未捕获的异常&#39; InvalidArgumentException&#39;消息&#39;无效的响应字符串&#39;在/srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/psr7/src/functions.php:478堆栈跟踪:#0 /srv/www/vhosts/internal.kingscredit .com / includes / ringcentral-php-master / vendor / ringcentral / ringcentral-php / src / Http / ApiResponse.php(56):RingCentral \ Psr7 \ parse_response(&#39; HTTP / 1.1 0 OK \ r \ n&# 39;)#1 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Http/Client.php(99):RingCentral \ SDK \ Http \ ApiResponse-&gt; __ construct(Object(RingCentral \ Psr7 \ Request),false,0)#2 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php /src/Http/Client.php(25):RingCentral \ SDK \ Http \ Client-&gt; loadResponse(Object(RingCentral \ Psr7 \ Request))#3 /srv/www/vhosts/internal.kingscredit.com/includes/ ringcentral-php-master / vendor / ringcentral / ringcentral-php / src / Platform / Platform.php(214):RingCentral \ SDK \ Http \ Client-&gt;在第44行的/srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Http/Client.php

答案 2 :(得分:0)

您可以验证CURLOPT_SSL_VERIFYPEER是否设置正确。

您可以参考此问题获取更多信息: Setting CURLOPT_SSL_VERIFYPEER

答案 3 :(得分:0)

我添加了curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);在client.php的第73行,它没有任何区别。

致命错误:/srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/psr7/src/functions中带有“无效响应字符串”消息的未捕获异常“InvalidArgumentException”。 php:478 Stack trace:#0 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Http/ApiResponse.php(56):RingCentral \ Psr7 \ parse_response('HTTP / 1.1 0 OK \ r \ n')#1 /srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Http /Client.php(99):RingCentral \ SDK \ Http \ ApiResponse-&gt; __ construct(Object(RingCentral \ Psr7 \ Request),false,0)#2 /srv/www/vhosts/internal.kingscredit.com/includes/ ringcentral-php-master / vendor / ringcentral / ringcentral-php / src / Http / Client.php(25):RingCentral \ SDK \ Http \ Client-&gt; loadResponse(Object(RingCentral \ Psr7 \ Request))#3 / srv /www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Platform/Pl atform.php(214):RingCentral \ SDK \ Http \ Client-&gt;在第44行的/srv/www/vhosts/internal.kingscredit.com/includes/ringcentral-php-master/vendor/ringcentral/ringcentral-php/src/Http/Client.php