Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve the user who has commented on a page post using Graph API, you can use the following steps:

  1. Get the post ID: You'll need to know the ID of the post for which you want to retrieve the comments. You can get the post ID by using the /{page-id}/feed endpoint or by visiting the page and finding the post ID in the URL.

  2. Get the comments: Once you have the post ID, you can use the /{post-id}/comments endpoint to retrieve the comments for that post. This will return an array of comment objects.

  3. Retrieve the user data: Each comment object will contain a "from" field which includes information about the user who posted the comment, including their name and profile picture. You can use this information to retrieve additional user data, such as their ID or email, by using the /{user-id} endpoint or the /search endpoint.

Here's an example of how you can retrieve the user who has commented on a page post using Graph API in Python:

import facebook

# Set up the Graph API client
graph = facebook.GraphAPI(access_token='YOUR_ACCESS_TOKEN', version='3.0')

# Get the post ID
post_id = 'POST_ID'

# Get the comments for the post
comments = graph.get_connections(id=post_id, connection_name='comments')

# Loop through the comments and retrieve the user data for each comment
for comment in comments['data']:
    user_data = graph.get_object(id=comment['from']['id'], fields='id,name,email')
    print(user_data)

This script will print out the ID, name, and email of each user who has commented on the post. Note that you'll need to replace 'YOURACCESSTOKEN' with a valid access token for your app, and 'POST_ID' with the ID of the post you want to retrieve the comments for.