目前,我正在致力于将聊天API (称为pusher Chatkit)集成到我正在开发的应用程序中。对于后端,使用PHP和laravel,使用postman测试服务器。在Postman上测试时,我收到一个500内部服务器错误,异常如下:
{
"message": "You must provide an instance_locator",
"exception": "Chatkit\\Exceptions\\MissingArgumentException",
"file": "/Users/shaquilenoor/Desktop/chatapi/vendor/pusher/pusher-chatkit-server/src/Chatkit.php",
"line": 49,
"trace": [
在trace中,有很多文件/行被引用,所以我省略了,因为这篇文章太多了(如果需要的话,你可以问,我可以用它做一个Gdrive链接)
指向要引用的line +函数的代码如下:
<?php
namespace Chatkit;
use Chatkit\Exceptions\ChatkitException;
use Chatkit\Exceptions\ConfigurationException;
use Chatkit\Exceptions\ConnectionException;
use Chatkit\Exceptions\MissingArgumentException;
use Chatkit\Exceptions\TypeMismatchException;
use Firebase\JWT\JWT;
class Chatkit
{
protected $settings = array(
'scheme' => 'https',
'port' => 80,
'timeout' => 30,
'debug' => false,
'curl_options' => array(),
);
protected $logger = null;
protected $ch = null; // Curl handler
protected $api_settings = array();
protected $authorizer_settings = array();
protected $cursor_settings = array();
const GLOBAL_SCOPE = 'global';
const ROOM_SCOPE = 'room';
/**
*
* Initializes a new Chatkit instance.
*
*
* @param array $options Options to configure the Chatkit instance.
* instance_locator - your Chatkit instance locator
* key - your Chatkit instance's key
* scheme - e.g. http or https
* host - the host; no trailing forward slash.
* port - the http port
* timeout - the http timeout
*/
public function __construct($options)
{
$this->checkCompatibility();
if (!isset($options['instance_locator'])) {
throw new MissingArgumentException('You must provide an instance_locator');
}
if (!isset($options['key'])) {
throw new MissingArgumentException('You must provide a key');
}
$this->settings['instance_locator'] = $options['instance_locator'];
$this->settings['key'] = $options['key'];
$this->api_settings['service_name'] = 'chatkit';
$this->api_settings['service_version'] = 'v2';
$this->authorizer_settings['service_name'] = 'chatkit_authorizer';
$this->authorizer_settings['service_version'] = 'v2';
$this->cursor_settings['service_name'] = 'chatkit_cursors';
$this->cursor_settings['service_version'] = 'v2';
foreach ($options as $key => $value) {
// only set if valid setting/option
if (isset($this->settings[$key])) {
$this->settings[$key] = $value;
}
}
}
instance_locator指的是在Pusher Chatkit上生成的代码,我将其链接到我的文件中,以便集成该API。这是我第一次使用PHP集成后端服务器,所以有点迷路了!我将感谢一些关于我应该在哪里解决这个问题的建议,也非常乐意提供进一步的信息。干杯
发布于 2019-02-06 05:13:37
根据您创建API请求的方式,您应该这样做:
$chatkit = new Chatkit(['instance_locator' => *locator*, 'key' => *actualKey*]);你得到的错误意味着你没有在数组中传递变量。
https://stackoverflow.com/questions/54542928
复制相似问题