Ruby on Rails Instagram宝石喜欢和评论计数无法正常工作 [英] Ruby on Rails Instagram Gem like and comment count not working properly

查看:114
本文介绍了Ruby on Rails Instagram宝石喜欢和评论计数无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历Instagram返回的数据并在网页上显示信息. 实际上,除了喜欢或评论数外,我几乎可以使每个领域都可以工作.由于某些原因,即使我通过返回的JSON进行查看,计数也明显不同,但对于所有字段,它总是返回相同的数字(2).其他所有内容均应正常工作.

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.

更具体地说,我正在使用Ruby on Rails Instagram Gem,并使用tag_recent_media(user)方法获取数据.

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  

在我的html.erb中:

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?

推荐答案

这是记录的错误可能源自保留字count.

建议可以通过使用嵌套的哈希表示法而不是点表示法来解决此问题:

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]

这篇关于Ruby on Rails Instagram宝石喜欢和评论计数无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆