Reputation: 111
How to get the page fan's comments from facebook-api graph using koala gem
@user_graph = Koala::Facebook::API.new('XXXXXXXXXXXXX')
lists = @user_graph.get_object("#{pageid}/insights/page_storytellers")
but i want to get the all comments of the page fan's comments.
its giving null array results, please anyone help me
Upvotes: 0
Views: 681
Reputation: 33
You can do this with koala gem.
access_token = '#{access_token}'
@graph = Koala::Facebook::API.new(access_token)
page_name = '#{page_name}'
node_type = "posts"
# get posts with standard content
posts_standard = @graph.get_connections(page_name, node_type,limit: 5)
# get posts with replies
posts = @graph.get_connections(page_name, node_type, limit: 5,fields: "message,id,created_time,updated_time,likes.summary(true),shares,comments.fields(comments.fields(from,message),message,from),from")
Upvotes: 0
Reputation: 560
Storytellers is a count of the unique people who created a story about your page post, it does not give you the full comment or info about the fan.
To get the comments on a page, you would have to first get a list of page posts, then query each post for comments.
You can get this info from any page, you do not need to have access to Insights.
For example:
page_info = @graph.get_object('nytimes')
pageid = page_info["id"]
fb_params = {
:fields => 'admin_creator,from,id,link,message,object_id,source,
status_type,story,story_tags,to,type,created_time,updated_time,
shares,likes.summary(true),comments.summary(true)',
:limit => 100,
:until => DateTime.now.at_end_of_day.to_i,
:since => DateTime.now.years_ago(5).to_i,
:metadata => 1
}
posts = @graph.get_connection(pageid, 'feed', fb_params)
If you include "comments.summary(true)" in the fields you request, you will get the first 25 comments on each post along with paging information (cursors, next and previous URLs).
Loop through each post and each post comment (and if you're up for it, comments on those comments), and you will have your result set.
If you prefer to skip writing the code, you could use Analytics Canvas to accomplish this task with a few clicks.
Full disclosure - I work with nModal on Analytics Canvas
Upvotes: 0