Python Facebook API - cursor pagination

后端 未结 3 1453
傲寒
傲寒 2021-02-09 08:10

My question involves learning how to retrieve my entire list of friends using Facebook\'s Python API. The current result returns an object with limited number of friends

3条回答
  •  孤街浪徒
    2021-02-09 09:03

    Meanwhile I was searching answer here is much better approach:

    import facebook
    access_token = ""
    graph = facebook.GraphAPI(access_token = access_token)
    
    totalFriends = []
    friends = graph.get_connections("me", "/friends&summary=1")
    
    while 'paging' in friends:
        for i in friends['data']:
            totalFriends.append(i['id'])
        friends = graph.get_connections("me", "/friends&summary=1&after=" + friends['paging']['cursors']['after'])
    

    At end point you will get one response where data will be empty and then there will be no 'paging' key so at that time it will break and all the data will be stored.

提交回复
热议问题