Twilio IP消息传递API无法正常工作

时间:2016-04-08 08:22:15

标签: javascript api ip twilio messaging

我只是按照说明进行设置和测试。我使用了Javascript API。当我尝试使用文档中提到的两个选项卡或两个窗口进行消息时,它无法正常工作。它会在sendMessage方法“undefined”时抛出错误。当我控制日志时,它会在html元素中输入正确的消息。

一旦我启动localhost,就会抛出以下错误。请提出任何建议。

导航至http://localhost:3000/

cds.twilio.com/v2/Streams:1 POST https://cds.twilio.com/v2/Streams 403 (Forbidden)
twilio-ip-messaging.min.js:198 IPMSG: failed to create session Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}(anonymous function) @ twilio-ip-messaging.min.js:198
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
undefined:1 Uncaught (in promise) Object {status: 403, description: "Forbidden", body: "{"message":"Access forbidden","status":403}"}
twilio-ip-messaging.min.js:199 Twilsock connection closed by server []r._onSocketRejected @ twilio-ip-messaging.min.js:199d.create.callbacks.onsocketRejected @ twilio-ip-messaging.min.js:199e.doCallback @ twilio-ip-messaging.min.js:281e.afterThisEvent @ twilio-ip-messaging.min.js:281e.afterEvent @ twilio-ip-messaging.min.js:281transition @ twilio-ip-messaging.min.js:281(anonymous function) @ twilio-ip-messaging.min.js:281r.onmessage @ twilio-ip-messaging.min.js:199

1 个答案:

答案 0 :(得分:2)

Twilio开发者传道者在这里。

首先,您需要使用您的生产帐户Sid才能使其生效。

Twilio test credentials only work on certain parts of the REST API

在服务器端生成令牌后,您需要将其发送到客户端并对客户端进行身份验证,如下所示:

accessManager = new Twilio.AccessManager(token);
messagingClient = new Twilio.IPMessaging.Client(accessManager);

看看IP Messaging quick start code to see an example of how it is doneThe full instructions for the quick start guide can be found here

让我知道这是否有帮助。