0

我正在使用 twilio 处理视频功能。我有这样的代码,

文件index.php

require_once('vendor/autoload.php'); 
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;

// Substitute your Twilio AccountSid and ApiKey details
$accountSid = 'ACxxxxxxxxxxxxxxxxxx';
$apiKeySid = 'SKxxxxxxxxxxxxxxxxxxx';
$apiKeySecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$identity = 'chatroom';

// Create an Access Token
$token = new AccessToken(
    $accountSid,
    $apiKeySid,
    $apiKeySecret,
    3600,
    $identity
);

// Grant access to Video
$grant1 = new VideoGrant();
$grant1->setRoom('php');
$token->addGrant($grant1);

// Serialize the token as a JWT
echo $token->toJWT();

有了这个,我得到了访问令牌,我正在使用下面的代码:

本地.js

var accessToken = 'token';
var accessManager = Twilio.AccessManager(accessToken);
//console.log(accessManager);
var client = Twilio.Conversations.Client(accessManager);

// Begin listening for invites to Twilio Video conversations.
client.listen().then(function() {
  client.on('invite', function(invite) {
    invite.accept().then(onInviteAccepted);
  });
});

但我收到这样的错误

SIP/2.0 403 Forbidden
CSeq: 81 REGISTER
Call-ID: pgilp7ph926lumbhvn9
From: <sip:chatroom@ACac8904e851929e0f1e5f39457540d.endpoint.twilio.com>;tag=77troiv7s5
To: <sip:chatroom@ACac8904e851929e0f1e5f39457540d.endpoint.twilio.com>;tag=12029129_f28f532c_80fa4-ec12-4818-8a18-f4a4fe766
Via: SIP/2.0/WSS 127.0.0.1:49162;branch=z9hG4bK877168;rport=49162
Server: Twilio
X-Twilio-Error: 20101 Invalid Access Token
Content-Length: 0
4

1 回答 1

0

首先你需要确保你的 API key、Secret key 和 account SID 是正确的。其次,该错误表明您使用上述三个数据点生成的密钥不正确/不被 Twilio 接受。要检查令牌在结构上是否正确,请访问此处

于 2020-07-05T09:30:49.853 回答