能力令牌无效或缺失 Twilio

问题描述

我已经集成了 Twilio 可编程语音。现在我试图让客户端从浏览器调用,并使用 Twilio JS 客户端 接收对浏览器的调用。当我尝试拨打电话时,它说。

消息:“能力令牌无效或缺失。”

我也搜索了互联网和 Twilio 文档,但没有任何帮助。这是我的代码

查看

<button onclick="callCustomer('{{ '+xxxxxxxx' }}')" type="button" class="btn btn-primary btn-lg call-customer-button">
     Call customer
</button>

控制器

public function newToken(Request $request) {
    // required for all Twilio access tokens
    $twilioAccountSid = 'ACxxxxxxxxx';
    $twilioApiKey = 'SKxxxxxxxxxxx';
    $twilioApiSecret = 'xxxxxx';

    $outgoingApplicationSid = 'APxxxxxxxxxxx';
    $identity = "Jhon_Doe";

    $token = new Accesstoken(
            $twilioAccountSid,$twilioApiKey,$twilioApiSecret,3600,$identity
    );

    $voiceGrant = new VoiceGrant();
    $voiceGrant->setoutgoingApplicationSid($outgoingApplicationSid);

    $voiceGrant->setIncomingallow(true);

    $token->addGrant($voiceGrant);

    return $token->toJWT();
}

JS

function callCustomer(phoneNumber) {
    $.get("/token",{forPage: window.location.pathname},function (data) {
        console.log(data);
        const device = new Twilio.Device();
        device.setup(data);
        
        var params = {"phoneNumber": phoneNumber};
        device.connect(params);
    });
}

我尝试从 jwt.io 调试工具调试我的令牌,它说:

无效签名。

我确定我遗漏了一些东西,但不知道是什么。任何帮助或提示将不胜感激。

解决方法

我已经想通了,只是发布答案以供将来参考。问题是 twilio js 版本。我已经包含了导致问题的旧版本。迄今为止的最新版本是版本:1.13。此版本已弃用能力令牌,现在使用访问令牌。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...