X-Twilio错误:20101无效的访问令牌

时间:2020-06-23 16:46:23

标签: twilio twilio-conversations

我正在使用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();

有了这个,我获得了访问令牌,并且将其与下面的代码一起使用:

local.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

1 个答案:

答案 0 :(得分:0)

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

相关问题