Get the hashtag using twitter gem

假如想象 提交于 2019-12-12 02:08:10

问题


I am using twitter gem to stream tweets in ruby. My code is

client.filter(:track => topics.join(",")) do |object|
  if(object.is_a?(Twitter::Entities))
  puts object.text if object.is_a?(Twitter::Tweet)
  puts object.created_at
  puts object.hashtags.to_s
  puts object.user.name
end
end

I need to fetch the hashtags in the tweet, if i use the above code I am getting the output as

 [#<Twitter::Entity::Hashtag:0x007ff23a06d4c8 @attrs={:text=>"coffee", :indices=>[20, 27]}>, #<Twitter::Entity::Hashtag:0x007ff23a06d450 @attrs={:text=>"mornings", :indices=>[28, 37]}>, #<Twitter::Entity::Hashtag:0x007ff23a06d428 @attrs={:text=>"cantstopmoving", :indices=>[38, 53]}>]

is there a way to fetch the individual hashtags


回答1:


object.hashtags.each do |p|
  puts "HashTags " +p.text.to_s
end


来源:https://stackoverflow.com/questions/29018207/get-the-hashtag-using-twitter-gem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!