我在使用“twitter”gem 的 Ruby 脚本中遇到错误。我的脚本中产生错误的部分是
require 'twitter'
require 'net/http'
require 'json'
#### Get your twitter keys & secrets:
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
Twitter.configure do |config|
config.consumer_key = 'xxxxxxx'
config.consumer_secret = 'xxxxxxx'
config.oauth_token = 'xxxxxx'
config.oauth_token_secret = 'xxxxxxx'
end
错误说undefined method 'configure' for Twitter:Module (NoMethodError)
然而,“twitter”和“json”gems 都在我的 gemfile 中,所以我不确定为什么这个方法是未定义的。
您正在以“旧”方式进行操作。从版本 5 开始,全局配置不再可用。因此,基本上您需要在初始化客户端时传递配置参数。
例如:
client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.access_token = "YOUR_ACCESS_TOKEN"
config.access_token_secret = "YOUR_ACCESS_SECRET"
end
然后只需使用该客户端进行查询,例如:
client.sample do |tweet|
puts tweet.text
end
欲了解更多信息,请参阅Sferik 的 Twitter 宝石
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)