【问题标题】:Capability token is not valid or missing Twilio功能令牌无效或缺少 Twilio
【发布时间】:2020-12-23 07:49:20
【问题描述】:

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

消息:“功能令牌无效或丢失。”

我也搜索了互联网和 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 调试工具调试我的令牌,它说:

签名无效。

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

【问题讨论】:

    标签: jwt twilio twilio-php twilio-click-to-call twilio-programmable-voice


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多