Search code examples
javascriptfacebookfacebook-pagebrowser-extension

How to filter out the most active users from fan page?


I am creating a new website. I want to promote it using another my topic-related web service. I want to send some gifts to people which popularized my first website and fanpage. How to filter out lets say 20 users which likes/shares/comments most of my posts?

Any suitable programming language will be good.

[EDIT]

Ok... to be honest I looking a way to parse a fanpage that is not mine. I want to send gifts to the most active users of fanpage of my competition, to simply bribe them a little :)


Solution

  • There are a number of ways, I'll start with the easiest...

    1. Say there's a brand name or #hashtag involved then you could user the search API as such: https://graph.facebook.com/search?q=watermelon&type=post&limit=1000 and then iterate over the data, say the latest 1000 (the limit param) to find out mode user (the one that comes up the most) out of all the statuses.

    2. Say it's just a page, then you can access the /<page>/posts end point (eg: https://developers.facebook.com/tools/explorer?method=GET&path=cocacola%2Fposts) as that'll give you a list of the latest posts (they're paginated so you can iterate over the results) and this'll include a list of the people who like the posts and who comment on them; you can then find out the mode user and so on.

    In terms of the code you can use anything, you can even run this locally on your machine using a simple web server (such as MAMP or WAMP, etc...) or CLI. The response is all JSON and modern languages are able to handle this. Here's a quick example I knocked up for the first method in Python:

    import json
    import urllib2
    from collections import Counter
    
    def search():
      req = urllib2.urlopen('https://graph.facebook.com/search?q=watermelon&type=post')
      res = json.loads(req.read())
      users = []
    
      for status in res['data']:
        users.append(status['from']['name'])
    
      count = Counter(users)
    
      print count.most_common()
    
    if __name__ == '__main__':
      search()
    

    I've stuck it up on github if you want to refer to it later: https://github.com/ahmednuaman/python-facebook-search-mode-user/blob/master/search.py

    When you run the code it'll return an ordered list of the mode users within that search, eg the ones who've posted the most comments with the specific search tag. This can be easily adapted for the second method should you wish to use it.