2017-08-10 93 views
3

我正在使用twilio并获取:错误未定义的方法`帐户'为Twilio。Twilio的未定义方法`帐户'

client = Twilio::REST::Client.new('twilio_sid','twilio_token') 
    # Create and send an SMS message 
    client.account.sms.messages.create(
    from: "+12345678901", 
    to: user.contact, 
    body: "Thanks for signing up. To verify your account, please reply HELLO to this message." 
) 

回答

3

您在连锁通话中错过了api。试试这个:

client.api.account.messages.create(
    from: "+12345678901", 
    to: user.contact, 
    body: "Thanks for signing up. To verify your account, please reply HELLO to 
    this message." 
) 
+0

https://github.com/twilio/twilio-ruby/wiki/Ruby-Version-5.x-Upgrade-Guide – Sajin

0

应该是:

client.api.account.messages.create 
1

会推荐这里查看Twilio的文档:

https://www.twilio.com/docs/guides/how-to-send-sms-messages-in-ruby

已经有一些变化与红宝石助手库5.x的(需要注意的是旧版本4.x版将只支持到17年10月15日 - 看到废弃的通知。)

随着5.x中,可以发送短信如下:

# set up a client to talk to the Twilio REST API 
@client = Twilio::REST::Client.new(account_sid, auth_token) 

@message = @client.messages.create(
    from: '+15017250604', 
    to: '+15558675309', 
    body: 'This is the ship that made the Kessel Run in fourteen parsecs?' 
) 

我使用这种方法到目前为止与twilio-ruby gem v5.2.1一起工作。

+0

阅读文档被开发人员高估,通常没有帮助! – thedanotto