0
使用Twilio Ruby gem,我從表單視圖助手內部傳遞'to'和'body'的參數:message,我默認並設置'from'代碼中的數字,但每個我運行它時,我得到:twilio api每次都要求'FROM'號碼
Twilio :: REST :: RequestError在MessagesController#創建
A「從」電話號碼是必需的。
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
如果遇到任何其他問題,你會得到意想不到的結果,你可以使用它來檢查你的API調用:https://www.runscope.com/docs/code-examples/twilio(是的無恥的插件我知道:) –