我正在通过以下存储库试用Twilio可编程聊天api:https://github.com/TwilioDevEd/ipm-quickstart-ruby
此时,它正在验证服务器中生成的令牌。
然而,我尝试了用node编写的另一个聊天演示,它工作得很好:https://github.com/twilio/twilio-chat-demo-js
我的项目是Ruby。我正在寻找来自Twilio或这里的社区的人的任何见解,他们已经解决了这个问题,可以为我指出正确的方向,让应用程序启动和运行。
发布于 2017-01-28 21:18:51
这是一个很难解决的问题。
客户端期望JWT令牌中授权散列下的push_credentials_sid密钥。
这是解决这个问题的代码:
app.rb
# 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
endhttps://stackoverflow.com/questions/41909038
复制相似问题