谁分享我的Facebook帖子?

问题描述:

使用任何Facebook API for Python,我试图让分享我的帖子的人数和这些人是谁。我目前有第一部分。

Using any Facebook API for Python, I am trying to get the # of people who shared my post and who those people are. I currently have the first part..

>>> from facepy import *
>>> graph = GraphAPI("CAAEr")
>>> g = graph.get('apple/posts?limit=20')
>>> g['data'][10]['shares']

得到计数,但是想要知道这些人是谁。

That gets the count, but I want to know who those people are.

sharedposts 给你更多关于一个职位股份的信息。您必须 GET USER_ID?fields = sharedposts 。此信息不会显示在文档中。

The sharedposts connection will give you more information about the shares of a post. You have to GET USER_ID?fields=sharedposts. This information doesn't appear in the doc.

这遵循你的代码:

# Going through each of your posts one by one
for post in g['data']:

    # Getting post ID
    id = post['id']   # Gives USERID_POSTID
    id[-17:]          # We know that a post ID is represented by 17 numerals

    # Another Graph request to get the shared posts
    shares = graph.get(id + '?fields=sharedposts')  

    print('Post' id, 'was shared by:')

    # Displays the name of each sharer
    print share['from']['name'] for share in shares['data']

这是我第一次Python中,代码中可能会出现一些语法错误。但是你得到了这个想法。

It is my first time with Python, there might be some syntax errors in the code. But you got the idea.