目前,我正在努力将聊天API(称为推送聊天套件(集成到我正在开发的应用程序。对于后端,正在使用PHP和laravel,并且使用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": [
在跟踪中,引用了许多文件/行,所以我省略了,因为它太多了,不适合这篇文章(如果需要,你可以问一下,我可以用它制作一个 Gdrive 链接(
导致所引用的行 + 函数的代码是这样的:
<?php
namespace Chatkit;
use ChatkitExceptionsChatkitException;
use ChatkitExceptionsConfigurationException;
use ChatkitExceptionsConnectionException;
use ChatkitExceptionsMissingArgumentException;
use ChatkitExceptionsTypeMismatchException;
use FirebaseJWTJWT;
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 集成后端服务器,所以有点迷茫!希望得到一些关于我应该在哪里解决问题的建议,也非常乐意提供更多信息。干杯
根据您创建 API 请求的方式,您应该执行以下操作:
$chatkit = new Chatkit(['instance_locator' => *locator*, 'key' => *actualKey*]);
您收到的错误意味着您尚未在数组中传递变量。