これはトラブルシューティングするのが難しい問題でした。
クライアントは、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