问题
I am trying to loop through data returned by Instagram and display information on a web page. I can get literally every field to work EXCEPT for like or comment count. For some reason, it always returns me the same number (2) for all the fields, even though if I look through the JSON returned the counts are clearly different. Everything else works properly as it should.
More specifically, I am using the Ruby on Rails Instagram Gem, getting data using the tag_recent_media(user) method.
def index
result = []
next_id = nil
while result.length < 100
data = Instagram.tag_recent_media(4, max_id: next_id)
next_id = data.pagination.next_max_id
result.concat(data)
end
@results = result.paginate(:page => params[:page], :per_page => 30)
end
in my html.erb:
<% @results.each do |instagram| %>
instagram.images.standard_resolution.url //gives me image url correctly
instagram.caption.text //gives me caption text correctly
instagram.user.username //gives me the username correctly
instagram.likes.count //always gives me 2!
instagram.comments.count //always gives me 2!
<%end %>
anyone have any idea what might be going on?
回答1:
This is a documented bug in the behavior of the Instagram Ruby Gem, possibly stemming from the word count
being reserved.
It is suggested that the issue can be resolved by using a nested hash notation, rather than dot notation:
instagram.likes[:count]
instagram.comments[:count]
回答2:
Do a puts instagram.likes
and puts instagram.comments
. My bet is that likes and comments are returning an array or hash and you will need to go one level deeper to get the actual counts.
来源:https://stackoverflow.com/questions/21896500/ruby-on-rails-instagram-gem-like-and-comment-count-not-working-properly