Animesh Pandey
Animesh Pandey

Reputation: 6018

How to access a secret group's posts using facebook-api?

I am a part of a secret group. I want to get all of the posts and their metadata. I use the following code:

import facebook

if __name__ == '__main__':

    APP_SECRET = ""
    APP_ID = ""
    PAGE_ID = "" ## Page ID of the secret group
    access_token = facebook.get_app_access_token(APP_ID, APP_SECRET)

    graph = facebook.GraphAPI(access_token)
    resp = graph.get_object('me/accounts')
    page_access_token = None
    for page in resp['data']:
        if page['id'] == PAGE_ID:
            page_access_token = page['access_token']
    graph = facebook.GraphAPI(page_access_token)

but I get this error:

facebook.GraphAPIError: An active access token must be used to query information about the current user.

on line resp = graph.get_object('me/accounts').

Where am I going wrong?

Upvotes: 1

Views: 534

Answers (1)

andyrandy
andyrandy

Reputation: 73984

The error message means that you did not authorize the user. How to do that: https://developers.facebook.com/docs/facebook-login/

/me/accounts is the endpoint to get access to pages, for groups you need the user_managed_groups permission and the /me/groups endpoint. You need to use an active User Token for that, of course.

More information: https://developers.facebook.com/docs/graph-api/reference/v2.4/user/groups

Upvotes: 1

Related Questions