我一直在ruby中使用twitter gem来获取推文的各种属性。我成功地获取了所有属性。但是,当我尝试获取转推时,它总是给我0的值。
require 'twitter'
geolocate = Twitter::Geo.new
client = Twitter::Streaming::Client.new do |config|
config.consumer_secret ="XXXXXXXXXXXXXXXXX"
config.consumer_key = "YYYYYYYYYYYYYYYYY"
config.access_token ="ZZZZZZZZZZZZZZZZZ"
config.access_token_secret ="AAAAAAAAAAAAAAAAA"
end
client.filter(:locations => "-122.75,36.8,-121.75,37.8,-74,40,-73,41,-84.32,33.84,-75.45,36.58") do |object|
if(object.is_a?(Twitter::Entities))
if (object.geo.longitude.nil? == false)
if(object.hashtags?)
puts "Tweet: " +object.text.to_s if object.is_a?(Twitter::Tweet)
puts "Created At: " +object.created_at.to_s
puts "UserName: " +object.user.name.to_s
puts "retweets: " +object.retweet_count.to_s
end
end
end
end
转发总是给我零值的价值 以下是某些用户的示例输出。
Tweet: #stevienicks #vibez champagne satin shirt/vest with tail... Has back waist tie, small/medium $32… https://t.co/m7I1rTEUeM
Created At: 2015-04-15 08:03:20 -0400
UserName: MAHPs Vintage
retweets: 0
______________________________________________
Tweet: Kicking off day 2 of our spring leadership conference with a continuation of @JohnCMaxwell 's 5 levels of #leadership http://t.co/hNNC0tdYni
Created At: 2015-04-15 08:03:20 -0400
UserName: Hendrick Automotive
retweets: 0
_____________________________________________
Tweet: Thanks God for another day!
Obrigado Deus por mais um dia
#GoodMorning… https://t.co/klMwtfr7w3
Created At: 2015-04-15 08:03:29 -0400
UserName: Leonnardo Lima
retweets: 0
______________________________________________
Tweet: #duke #whereisthegiraffeemoji #champs @ Monroe your Boat ⛵️ https://t.co/bw1AV67GMY
Created At: 2015-04-15 08:03:30 -0400
UserName: Gossip Garner
retweets: 0
有没有办法让特定用户转发
非常感谢任何帮助。
答案 0 :(得分:0)
retweet_count
方法返回只读整数。如图所示是文档Ruby's Tweet documentation。我想这是不可改变的。
你应该试试这个puts "retweets: #{object.retweet_count}"
。
此外,您不需要将每个属性更改为字符串以进行打印。只需按照上面的说明使用它就可以了。