[英]Fetching retweet using twitter gem in ruby
我一直在使用ruby中的twitter寶石來獲取tweet的各種屬性。 我已經成功獲取了所有屬性。 但是,當我嘗試獲取轉發時,它始終為我提供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
那么有沒有辦法獲得特定用戶的轉發
任何幫助深表感謝。
retweet_count
方法返回一個只讀整數。 如圖所示,文檔為Ruby的Tweet文檔 。 我想這是一成不變的。
您應該嘗試puts "retweets: #{object.retweet_count}"
。
另外,您無需將每個屬性都更改為字符串即可打印。 只需如上所示使用它,您就應該做好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.