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

Twilio可编程聊天Ruby快速入门。获取401错误,twilio,twilio-api,Twilio,Twilio Api,我正在通过此repo试用Twilio可编程聊天api: 目前,它正在验证服务器中生成的令牌 不过,我尝试了在node中编写的另一个聊天演示,效果很好: 我的项目是Ruby。我想从Twilio或社区的人那里得到一些见解,他们解决了这个问题,可以为我指出正确的方向,让应用程序启动并运行。这是一个很难解决的问题 客户端需要JWT令牌中的grant哈希下的push_credentials_sid密钥 这是解决问题的代码: app.rb # Generate a token for use in our

我正在通过此repo试用Twilio可编程聊天api:

目前,它正在验证服务器中生成的令牌

不过,我尝试了在node中编写的另一个聊天演示,效果很好:


我的项目是Ruby。我想从Twilio或社区的人那里得到一些见解,他们解决了这个问题,可以为我指出正确的方向,让应用程序启动并运行。

这是一个很难解决的问题

客户端需要JWT令牌中的grant哈希下的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
end