1

我正在使用 twilio 视频 javascript 服务。当我尝试收听端点时,它给出了一个错误:

{_errorData: Object, name: "LISTEN_FAILED", message: "Gateway responded with: 31201 Authentication failed"}

我正在使用以下代码生成访问令牌:

<?php
    require_once('/path/to/twilio-php/Services/Twilio.php');

    $accountSid = "ACC_SID";
    $signingKeySid = SID;
    $signingKeySecret = SECRET;

    $token = new Services_Twilio_AccessToken($signingKeySid, $accountSid, $signingKeySecret);
    $token->addEndpointGrant(ENDPOINT_NAME);
    $token->enableNTS();
    echo $token->toJWT();

?>

当我在我的 javascript 中使用这个令牌开始监听端点时,它给出了上述错误。

Javascript代码是:

endpoint = new Twilio.Endpoint(token);

endpoint.listen().then(init,function (error) {
    console.log('Could not connect to Twilio: ' + error.message);
});

但是,当我使用从 twilio 测试工具生成的令牌时,视频校准工作。我更新了我的 php twilio video sdk。但结果没有任何变化。这是之前的工作代码。不知道后来怎么样了!有没有人有解决这个问题的答案?

4

2 回答 2

1

这就是我所做的,适用于我的情况:

在我的 PHP 文件中,我有:

<?php
require_once('php/Services/Twilio.php'); // Loads the library

// You will need your Account Sid and a SigningKey Sid and Secret
// to generate an Access Token for your SDK endpoint to connect to Twilio.
$accountSid = "XXXX";
$signingKeySid = "YYYY";
$signingKeySecret = "ZZZZ";

$token = new Services_Twilio_AccessToken($signingKeySid, $accountSid, $signingKeySecret);
$token->addEndpointGrant("gonzalo");
$token->enableNTS();
?>

在我的 HTML 代码中:

<span id='twilio_token' style='display: none;'><?php echo $token->toJWT()?></span>

在我的 Javascript 中:

var accessToken = document.getElementById('twilio_token').innerHTML;
console.log(accessToken);
// create an Endpoint and connect to Twilio
endpoint = new Twilio.Endpoint(accessToken);
endpoint.listen().then(
  endpointConnected,
  function (error) {
    log('Could not connect to Twilio: ' + error.message);
  }
);

当您为 Twilio 令牌执行 console.log 时,它是否有效?

于 2015-10-12T23:32:28.203 回答
0

Twilio Video 也有同样的问题。就我而言,服务器的日期错误,因此生成的令牌无效。确定日期后,Twilio 身份验证再次开始工作。

于 2016-05-12T16:48:23.510 回答