当我发送任何消息时,它会出错。
Twilio::REST::RequestError: The requested resource /2010-04-01/Accounts/cafac01e41ad5fbad3da4ad8619c8d36/Messages.json was not found
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
@client.account.messages.create({
:from => 'xxxxxx',
:to => 'xxxxxx',
:body => 'Twilio Testing',
})
答案 0 :(得分:1)
除了Devin在关于您的网址中错误的帐户SID的评论中提出的潜在问题之外,以下代码示例可能会有所帮助。
设置Twilio-Ruby的代码:
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'
# put your own credentials here
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
# alternatively, you can preconfigure the client like so
Twilio.configure do |config|
config.account_sid = account_sid
config.auth_token = auth_token
end
# and then you can create a new client without parameters
@client = Twilio::REST::Client.new
然后是代码to send an SMS:
@client.messages.create(
from: '+1415XXXXXXX',
to: '+1610XXXXXXX',
body: 'Hey there!'
)