2017-08-10 73 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