首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twilio可编程聊天Ruby快速入门。获取401错误

Twilio可编程聊天Ruby快速入门。获取401错误
EN

Stack Overflow用户
提问于 2017-01-28 19:06:37
回答 1查看 86关注 0票数 1

我正在通过以下存储库试用Twilio可编程聊天api:https://github.com/TwilioDevEd/ipm-quickstart-ruby

此时,它正在验证服务器中生成的令牌。

然而,我尝试了用node编写的另一个聊天演示,它工作得很好:https://github.com/twilio/twilio-chat-demo-js

我的项目是Ruby。我正在寻找来自Twilio或这里的社区的人的任何见解,他们已经解决了这个问题,可以为我指出正确的方向,让应用程序启动和运行。

EN

回答 1

Stack Overflow用户

发布于 2017-01-28 21:18:51

这是一个很难解决的问题。

客户端期望JWT令牌中授权散列下的push_credentials_sid密钥。

这是解决这个问题的代码:

app.rb

代码语言:javascript
复制
# Generate a token for use in our IP Messaging application
get '/token' do
  # Get the user-provided ID for the connecting device
  device_id = params['device']

  # Create a random username for the client
  identity = Faker::Internet.user_name

  # Create a unique ID for the currently connecting device
  endpoint_id = "TwilioDemoApp:#{identity}:#{device_id}"

  # Create an Access Token for IP messaging usage
  token = Twilio::Util::AccessToken.new ENV['TWILIO_ACCOUNT_SID'],
    ENV['TWILIO_API_KEY'], ENV['TWILIO_API_SECRET'], 3600, identity

  # Create IP Messaging grant for our token
  grant = Twilio::Util::AccessToken::IpMessagingGrant.new
  grant.service_sid = ENV['TWILIO_IPM_SERVICE_SID']
  grant.push_credential_sid = 'CRe9c5eff29e744709d7df875f8a797bf0'
  grant.endpoint_id = endpoint_id
  token.add_grant grant

  # Generate the token and send to client
  json :identity => identity, :token => token.to_jwt
end
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41909038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档