【问题标题】:Twilio IP Messaging API not workingTwilio IP 消息传递 API 不工作
【发布时间】:2016-07-29 10:28:42
【问题描述】:

我只是按照说明进行设置和测试。我使用了 Javascript API。当我尝试使用文档中提到的两个选项卡或两个窗口发送消息时,它不起作用。它在 sendMessage 方法“未定义”时引发错误。当我在控制台登录时,它会在 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

【问题讨论】:

  • 这看起来您没有正确设置访问令牌,因此 Twilio 没有让您访问该服务。你能分享你用来验证 API 的代码吗?
  • @philnash。谢谢。这就是我使用的:
  • 我什么都没看到!可能最好用这些额外信息更新问题。
  • @philnash 谢谢。这就是我正在使用的' var ipmGrant = new IpMessagingGrant({ serviceSid: process.env.TWILIO_IPM_SERVICE_SID, endpointId: endpointId }); // 创建一个我们将签名并返回给客户端的访问令牌, // 包含我们刚刚创建的授权 var token = new AccessToken( process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET );'
  • 您使用的是生产还是测试帐户 Sid?以及如何在前端设置访问令牌?

标签: javascript api ip twilio messaging


【解决方案1】:

这里是 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.

让我知道这是否有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多