Twilio Ruby 发送短信 - 未定义的方法"消息"



我正在尝试通过Twilio API从我的Rails应用程序发送短信。我正在按照这里的说明进行操作(https://github.com/twilio/twilio-ruby),但我似乎无法弄清楚这一点。

这是我的轨道控制器中的代码

require 'twilio-ruby'
account_sid = '[I inserted account_sid here]'
auth_token = '[I inserted auth_token here]'
@client = Twilio::REST::Client.new(account_sid, auth_token)
@client.account.messages.create(
  from: '+[number here]',
  to: '+[number here]',
  body: 'Hey there!'
)

返回以下错误消息(出于简单的隐私原因,省略号)

NoMethodError .... undefined method `messages' for #<Twilio::REST::Account: ....

任何帮助将不胜感激。谢谢大家!

这里的Twilio布道者。

也可能是因为我们最近添加了消息资源并弃用了 SMS 资源。因此,您可能只需要将 gem 更新到最新版本。

$ gem update twilio-ruby

希望这有帮助!

你把吗 "特威利奥红宝石"在您的宝石文件中?

如果没有,请将其放入并捆绑

然后你可以删除 需要"特威利奥红宝石"从您的控制器

这是另一个教程 - https://www.twilio.com/blog/2012/02/adding-twilio-sms-messaging-to-your-rails-app.html

最新更新