我正在使用api文档中给出的twilio-ruby的以下示例。
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,我该如何处理响应?
提前致谢。
答案 0 :(得分: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