new Twilio.TaskRouter.Workspace()给出了WebSocket意外响应代码。403

问题描述 投票:0回答:1

所以我有以下代码。

<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '../vendor/autoload.php'; // Loads the library
use Twilio\Jwt\TaskRouter\WorkerCapability;

// Your Account Sid and Auth Token from twilio.com/user/account
$accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$capability = new WorkerCapability($accountSid, $authToken, $workspaceSid);
$capability->allowFetchSubresources();
$capability->allowActivityUpdates();
$capability->allowReservationUpdates();
$token = $capability->generateToken();
// By default, tokens are good for one hour.
// Override this default timeout by specifiying a new value (in seconds).
// For example, to generate a token good for 8 hours:
$token = $capability->generateToken(28800);  // 60 * 60 * 8
?>
<script type="text/javascript" src="//media.twiliocdn.com/taskrouter/js/v1.20/taskrouter.min.js"></script>
<script>
    var workspace = new Twilio.TaskRouter.Workspace("<?= $token ?>");
</script>

PHP代码能很好地生成一个标记 但JS却生成了以下错误。

WebSocket connection to '...' failed: Error during WebSocket handshake: Unexpected response code: 403

请问这是怎么回事?

谢谢!所以我有以下代码:PHP代码生成的token很好,但JS却生成了以下错误:有什么想法吗?

twilio twilio-api twilio-php
1个回答
1
投票

你设置了一个... WorkerCapability 中,但却想用SDK来使用它。Workspace 对象。 我相信你需要使用一个 WorkspaceCapability 标记,如果你想实例化一个新的 Workspace 对象。

© www.soinside.com 2019 - 2024. All rights reserved.