我正在尝试循环访问 Instagram 返回的数据并在网页上显示信息。 我几乎可以让每个领域工作,除了点赞或评论数。出于某种原因,它总是为所有字段返回相同的数字 (2),即使我查看返回的 JSON,计数明显不同。其他一切正常工作。
更具体地说,我正在使用 Ruby on Rails Instagram Gem,使用 tag_recent_media(user) 方法获取数据。
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
在我的 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 %>
有人知道会发生什么吗?
最佳答案
这是一个 documented bug在 Instagram Ruby Gem 的行为中,可能源于单词 count
被保留。
建议可以使用嵌套哈希表示法而不是点表示法来解决问题:
instagram.likes[:count]
instagram.comments[:count]
关于ruby-on-rails - Ruby on Rails Instagram Gem 点赞和评论计数无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21896500/