Twilio - 找不到请求的资源错误。发送短信时

Twilio - The requested resource not found error. when sending sms messages

当我发送任何消息时,它都会出错。

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',  
    })

除了 Devin 在评论中提出的关于您 Url 中不正确的帐户 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!'
)