【问题标题】:Twilio api asking for 'FROM' number each timeTwilio api 每次都要求“FROM”号码
【发布时间】:2013-09-24 17:14:44
【问题描述】:

使用 Twilio Ruby gem,我从 :message 中的表单视图助手传递“to”和“body”的参数,我在代码中默认并设置了“from”数字,但每次我运行它,我得到:

MessagesController#create 中的 Twilio::REST::RequestError

需要“发件人”电话号码。

class MessagesController < ApplicationController

(other methods in here as well)

def create


user = User.find(params[:user_id])
  @account_sid = '******'
  @auth_token = '**********'
  from = '+1347*****'
  body = params[:message][:body]
  to = params[:message][:to]
  from = '+1347******'
  @client = Twilio::REST::Client.new(@account_sid, @auth_token)

  # this sends the sms message 
  @client.account.sms.messages.create(body => :body, from => :from, to => :to)

  # this saves the form message in the model Message
  user.messages.create(body => :body, from => :from, to => :to)

  redirect_to '/'
end

【问题讨论】:

标签: ruby-on-rails api twilio


【解决方案1】:

您的哈希值似乎都倒退了

user.messages.create(body => :body, from => :from, to => :to)

应该阅读

user.messages.create(:body => body, :from => from, :to => to)

在您的示例中,您正在将值为 body、from 和 to 的键设置为符号 body、from、to。

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 2016-08-04
    • 2021-07-02
    相关资源
    最近更新 更多