2017-01-28 5 views
1

を取得する私は、このレポを通じてTwilioプログラマブルチャットAPIをしようとしています:https://github.com/TwilioDevEd/ipm-quickstart-rubyTwilioプログラマブルチャットRuby quickstart。 401エラー

現時点では、サーバーで生成されたトークンを検証低下しています。

は、しかし、私はノードで書かれた別のチャットのデモを試してみましたが、それだけで正常に動作します: https://github.com/twilio/twilio-chat-demo-js

私のプロジェクトはRubyです。私はこの問題を解決したTwilioまたはコミュニティの誰かからの洞察を求めており、アプリを起動して実行する正しい方向に向けることができます。

答えて

2

これはトラブルシューティングするのが難しい問題でした。

クライアントは、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 
関連する問題