Koala get like mail

I am currently using a koala and everything seems to work, although when I try to use the following to get something I like on certain posts, all I seem to get is an array of elements

code in application helper

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 

code inside view

 =likes_count(feed['id']) 

returned results

 {"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}}} 
+6
source share
2 answers

Likes the post:

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

In case someone stumbles upon this, and also, perhaps, will look for the number of shares and comments:

Shares in the message:

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

Comments on the post:

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

Or, if you prefer a hash of all three:

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

To get all the information about your message:

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

Try @graph.get_connections(post_id, "likes") to set up a Koala::Facebook::API::GraphCollection , on which you can call .next_page to go through the whole list of your favorites.

0
source

Source: https://habr.com/ru/post/971174/


All Articles