Search code examples
pythonfacebookfacebook-graph-apifacebook-group

How to get all content posted by a Facebook Group using Graph API


I am very new to the Graph API and trying to write a simple python script that first identifies all pages that a user has liked and all groups that he/she is a part of. To do this, I used the following:

To get the groups he has joined:

API: /{user-id}/groups 
Permissions req: user_groups 


To get the pages he has liked:

API: /{user-id}/likes 
Permissions req: user_likes

and 
    url='https://graph.facebook.com/'+userId+'/likes?access_token='+accessToken +'&limit='+str(limit)

Now that I can see the id's of the groups in the JSON output, I want to hit them one by one and fetch all content (posts, comments, photos etc.) posted within that group. Is this possible and if yes, how can I do it? What API calls do I have to make?


Solution

  • That's quite a broad question, before asking here you should have give a try searching on SO.

    Anyways, I'll tell you broadly how can you do it.

    First of all go through the official documentation of Graph API: Graph API Reference.
    You'll find each and every API which can be used to fetch the data. For example: /group, /page. You'll get to know what kind of access token with what permissions are required for an API call.

    Here are some API calls useful to you-

    • to fetch the group/page's posts- /{group-id/page-id}/posts

    • to fetch the comments of a post- {post-id}/comments

    • to fetch the group/page's photos- /{group-id/page-id}/photos

    and so on. Once you'll go through the documentation and test some API calls, the things would be much clear. It's quite easy!

    Hope it helps. Good luck!