0

我正在使用 twilio-ruby 的 api 文档中给出的以下示例。

http://www.twilio.com/docs/api/rest/usage-records#list-get-example-3

# twilio-ruby install docs at twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account 
account_sid = 'AC32a3c49700934481addd5ce1659f04d2'
auth_token = '{{ auth_token }}'
@client = Twilio::REST::Client.new account_sid, auth_token

# Loop over records and print out a property for each one
@client.account.usage.records.list({
  :category => "calls-inbound",
  :start_date => "2012-09-01",
  :end_date => "2012-09-30"}).each do |record|
  puts record.sid
end

(我正在更换正确的凭据,并将日期设置为我有呼入电话的日期)。

我正进入(状态

NoMethodError: undefined method `sid' for #<Twilio::REST::Record:0x007f8f2c94c948>

如果我删除对 .sid 的调用并检查响应,我会得到以下信息

[<Twilio::REST::Record @uri=/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxx/Usage/Records/>]

所以基本上是一个数组,其中一个成员具有 uri 属性。

所以。为什么最初的示例不起作用,如果不调用 .sid ,我该怎么处理响应?

提前致谢。

4

1 回答 1

2

网站上的 API 文档有误。

# twilio-ruby install docs at twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account 
account_sid = 'AC32a3c49700934481addd5ce1659f04d2'
auth_token = '{{ auth_token }}'
@client = Twilio::REST::Client.new account_sid, auth_token


# Loop over records and print out a property for each one
@client.account.usage.records.today.list.each do |record|
    puts record.category + ' : ' + record.usage
end

供参考:https ://github.com/twilio/twilio-ruby/issues/52

于 2013-07-15T15:06:05.783 回答