2014-06-22 88 views
6

我目前使用的考拉,似乎都在工作,雖然當試圖使用以下獲得某些帖子上的喜歡所有我似乎越來越是項目數組考拉在帖子上得到喜歡

應用助手內

代碼

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}}} 

回答

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') 
+1

所有3的哈希,洞察似乎不再工作。可以通過以下方式獲得相同的結果:'graph.get_object(post_id,:fields =>「shares,likes.summary(true),comments.summary(true)」) – riley

0

嘗試@graph.get_connections(post_id, "likes")暴露一個Koala::Facebook::API::GraphCollection對象,你可以調用.next_page到遍歷喜歡的整個列表。

相關問題