加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – koala喜欢帖子

发布时间:2020-12-16 23:15:57 所属栏目:百科 来源:网络整理
导读:我目前正在使用考拉,所有似乎都在工作,但当试图使用以下来获得某些帖子上的喜欢我似乎得到的是项目数组 应用程序助手中的代码 def facebook @facebook ||= Koala::Facebook::API.new(current_user.oauth_token) block_given? ? yield(@facebook) : @facebook
我目前正在使用考拉,所有似乎都在工作,但当试图使用以下来获得某些帖子上的喜欢我似乎得到的是项目数组

应用程序助手中的代码

def facebook
    @facebook ||= Koala::Facebook::API.new(current_user.oauth_token)
    block_given? ? yield(@facebook) : @facebook
  rescue Koala::Facebook::APIError
    logger.info e.to_s
    nil
  end

def likes_count obj
    facebook.get_object(obj,:fields => "likes.summary(true)")
  end

视图中的代码

=likes_count(feed['id'])

结果返回

{"id"=>"846011512095715","updated_time"=>"2014-06-22T11:11:45+0000","likes"=>{"data"=>[{"id"=>"10152444475716893","name"=>"Tahlia Fulton"},{"id"=>"10152240895519022","name"=>"Tim Raftery"},{"id"=>"481256765338477","name"=>"Gabby Taylor"},{"id"=>"664803753573900","name"=>"Harriet Ochsenbein"},{"id"=>"10152453604228810","name"=>"Kelly Jenkinson"},{"id"=>"10152145864189249","name"=>"David Glazzard"},{"id"=>"10203193488711772","name"=>"Bianca Love"},{"id"=>"10152567265688833","name"=>"Clare Duncan"},{"id"=>"105513176145556","name"=>"Frankston Hockey Club"}],"paging"=>{"cursors"=>{"after"=>"MTA1NTEzMTc2MTQ1NTU2","before"=>"MTAxNTI0NDQ0NzU3MTY4OTM="}},"summary"=>{"total_count"=>9}}}

解决方法

喜欢帖子:
likes = @graph.get_object('post_id',:fields => "likes.summary(true)")["likes"]["summary"]["total_count"]

如果有人碰到这个并且恰好正在寻找股票和评论数:

在帖子上分享:

shares = @graph.get_object('post_id',:fields => "shares")["shares"]["count"]

对帖子的评论:

comments = @graph.get_object('post_id',:fields => "comments.summary(true)")["comments"]["summary"]["total_count"]

或者如果您更喜欢这三种哈希:

post_kpis = @graph.get_connections(@post,'insights',metric: 'post_storytellers_by_action_type').first["values"].first["value"]

要获得有关您帖子的所有见解:

post_insights = @graph.get_connections(@post,'insights')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读