16

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 :)

noisy
  • 5,701
  • 9
  • 47
  • 86
  • 1
    You can't, facebook doesn't allow for pages to query their users – Fabio Antunes Apr 11 '13 at 15:58
  • @FabioAntunes I don't want to query users, but posts from page, and next read which users like post, which share it or comment. This information are available for everyone in FB page so in the worst scenario browser extension can be written, to parse opened fanpage. The question is there a better solution. – noisy Apr 11 '13 at 16:47
  • Oh in that case forget what I said, I'll post an answer later, right now I'm under some heavy work. But you must use FQL for this – Fabio Antunes Apr 11 '13 at 17:27
  • 1
    @FabioAntunes ... no answer from you related to this post... :-( – Csharp Apr 22 '13 at 22:08
  • i don't think that sending gifts to active users of another page is trustworthy at all. concentrate on your business and stay fair! – Johannes N. Apr 23 '13 at 10:09
  • 1
    @JohannesN. I guess you are not a PR guy? :) What's is wrong in sending gifts to anybody? :) – noisy Apr 24 '13 at 12:04

5 Answers5

4

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.

Ahmed Nuaman
  • 11,324
  • 13
  • 50
  • 80
  • 1
    This answer is not perfect, but it give me enough information to create that what I need, so bounty goes to you :) I will try enhance your code and paste link here later :) – noisy Apr 30 '13 at 11:00
4

Based on Ahmed Nuaman answer (please also give them +1), I have prepared this piece of code:

example of usage:

To analyze most active facebook users of http://www.facebook.com/cern

$ python FacebookFanAnalyzer.py cern likes

$ python FacebookFanAnalyzer.py cern comments

$ python FacebookFanAnalyzer.py cern likes comments

notes: shares and inner comments are not supported

file: FacebookFanAnalyzer.py

# -*- coding: utf-8 -*-
import json
import urllib2
import sys
from collections import Counter
reload(sys)
sys.setdefaultencoding('utf8')
###############################################################
###############################################################
#### PLEASE PASTE HERE YOUR TOKEN, YOU CAN GENERETE IT ON:
####    https://developers.facebook.com/tools/explorer
#### GENERETE AND PASTE NEW ONE, WHEN THIS WILL STOP WORKING

token = 'AjZCBe5yhAq2zFtyNS4tdPyhAq2zFtyNS4tdPw9sMkSUgBzF4tdPw9sMkSUgBzFZCDcd6asBpPndjhAq2zFtyNS4tsBphqfZBJNzx'

attrib_limit = 100
post_limit = 100
###############################################################
###############################################################


class FacebookFanAnalyzer(object):

    def __init__(self, fanpage_name, post_limit, attribs, attrib_limit):
        self.fanpage_name = fanpage_name
        self.post_limit = post_limit
        self.attribs = attribs
        self.attrib_limit = attrib_limit
        self.data={}

    def make_request(self, attrib):
        global token
        url = 'https://graph.facebook.com/' + self.fanpage_name + '/posts?limit=' + str(self.post_limit) + '&fields=' + attrib + '.limit('+str(self.attrib_limit)+')&access_token=' + token
        print "Requesting '" + attrib + "' data: " + url
        req = urllib2.urlopen(url)
        res = json.loads(req.read())

        if res.get('error'):
            print res['error']
            exit()

        return res

    def grep_data(self, attrib):
        res=self.make_request(attrib)
        lst=[]
        for status in res['data']:
            if status.get(attrib):
                for person in status[attrib]['data']:
                    if attrib == 'likes':
                        lst.append(person['name'])
                    elif attrib == 'comments':
                        lst.append(person['from']['name'])
        return lst


    def save_as_html(self, attribs):
        filename = self.fanpage_name + '.html'
        f = open(filename, 'w') 

        f.write(u'<html><head></head><body>')
        f.write(u'<table border="0"><tr>')
        for attrib in attribs:
            f.write(u'<td>'+attrib+'</td>')
        f.write(u'</tr>')

        for attrib in attribs:
            f.write(u'<td valign="top"><table border="1">')

            for d in self.data[attrib]:
                f.write(u'<tr><td>' + unicode(d[0]) + u'</td><td>' +unicode(d[1]) + u'</td></tr>')

            f.write(u'</table></td>')

        f.write(u'</tr></table>')
        f.write(u'</body>')
        f.close()
        print "Saved to " + filename

    def fetch_data(self, attribs):
        for attrib in attribs:
            self.data[attrib]=Counter(self.grep_data(attrib)).most_common()

def main():
    global post_limit
    global attrib_limit

    fanpage_name = sys.argv[1] 
    attribs = sys.argv[2:] 

    f = FacebookFanAnalyzer(fanpage_name, post_limit, attribs, attrib_limit)
    f.fetch_data(attribs)
    f.save_as_html(attribs)

if __name__ == '__main__':
    main()

Output:

Requesting 'comments' data: https://graph.facebook.com/cern/posts?limit=50&fields=comments.limit(50)&access_token=AjZCBe5yhAq2zFtyNS4tdPyhAq2zFtyNS4tdPw9sMkSUgBzF4tdPw9sMkSUgBzFZCDcd6asBpPndjhAq2zFtyNS4tsBphqfZBJNzx
Requesting 'likes' data: https://graph.facebook.com/cern/posts?limit=50&fields=likes.limit(50)&access_token=AjZCBe5yhAq2zFtyNS4tdPyhAq2zFtyNS4tdPw9sMkSUgBzF4tdPw9sMkSUgBzFZCDcd6asBpPndjhAq2zFtyNS4tsBphqfZBJNzx
Saved to cern.html

enter image description here

Community
  • 1
  • 1
noisy
  • 5,701
  • 9
  • 47
  • 86
2

Read the list of posts on the page at the page's /feed connection and track the user IDs of those users who posted and commented on each post, building a list of who does it the most often.

Then store those somewhere and use the stored list in the part of your system which decides who to send the bonuses to.

e.g.

http://graph.facebook.com/cocacola/feed returns all the recent posts on the cocacola page, and you could track the IDs of the posters, commenters, likers, to determine who are the most active users

Igy
  • 43,312
  • 8
  • 86
  • 115
  • 1
    Once you have a an ID you can use this [FQL](https://developers.facebook.com/docs/reference/fql/page_fan) to get more information – Jason Sperske Apr 22 '13 at 22:15
  • Note that obviously the above solution requires some user to be logged into FB to retrieve the queried information. – The Kraken Apr 22 '13 at 22:17
  • @TheKraken, the graph API uses oAuth, you could automate the generation of an oAuth token and parse out the JSON response – Jason Sperske Apr 22 '13 at 22:20
  • @JasonSperske Really? I wasn't aware; thanks for the correction. – The Kraken Apr 22 '13 at 22:22
  • @TheKraken, actually I deleted that comment, the data returned for the cocacola fan page made me want ot go back and check to be sure. Needs further research – Jason Sperske Apr 22 '13 at 22:25
  • Understood, thanks anyway. If you or anyone else comes up with a sure solution, I've posted a question at http://bit.ly/11wDZt7. Thanks! – The Kraken Apr 22 '13 at 22:32
  • The problem with `//feed` is that it also includes posts that users have written on the page. Since you're only after people who like or comment on posts that the page has made then `//posts` is a better solution; see my answer for a code example too. – Ahmed Nuaman Apr 29 '13 at 06:31
  • And there's also the search API that may be easier to deal with as it'll get a list of all the public conversations that are happening within Facebook. – Ahmed Nuaman Apr 29 '13 at 06:32
-2

write a php or jquery script which is executed when user clicks like or share on your website just before actually sharing/like to fb and record the user info and the post he/she shared/liked. Now you can track who shared your post the most.

PHP/Jquery script will act as middle man, so dont use facebook share/like script directly. I will try to find the code I have written for this method. I have used PHP & Mysql. Try to use JQuery this will give a better result in terms of hidding the process (I mean data will be recorded without reloading the page).

Abhishek Salian
  • 862
  • 2
  • 9
  • 25
  • Altough I think you answered it before the OP edited the question, but even if it was his page this is not a particularly reliable or efficient solution (and there are other ways to like/comment a page--say, directly on Facebook--that are outside your control). – diego nunes Apr 29 '13 at 00:34
-2

Your question is nice, but it is quite hard.. (Actually, in the beginning, there's a thing that came from my mind that this is impossible. So, I build a quite different solution...) One of the best ways is to create a network where your viewers can register in the form that required the official URLs of their social networking pages, and also, they could choose that they doesn't have this kind of network:

“Do you want to share some of our page? Please register here first..”

So, they can get a specific URL that they've wanted to share when they're in your website, but they doesn't know the they're in tracing when they visited that specific URL.. (Every time a specific URL get visited, an I.P. get tracked and the number of visits get ++1 in a database.) Give them a dynamic URL on the top of your website that's in text area of every pages to track them. Or use scripting to automated the adding of a tracing query string on the URLs of your site.

I think there's a free software to build an affiliate network to make this easy! If your viewers really love your website, they'll registered to be an affiliate. But this thing is different, affiliate network is quite different from a network that mentioned in the paragraphs above..

But I think, you can also use Google Analytics to fully trace some referrals that didn't came from the URLs with dynamic QUERY STRING like Digital Point, but not from the other social network like Facebook 'cause you wouldn't get the exact Referral Paths with that kind of social network because of the query path. However you can use it to track the other networks. Also, AddThis Analytics is good for non-query string URLs.

The two kinds of referrals on Google Analytics are under of “Traffic Sources” menu of STANDARD REPORTS..

  • Traffic Sources
    • Sources
      • Referrals
    • Social
      • Network Referrals

This answer is pretty messy, but sometimes, quite useful.. Other than that? Please check these links below:

  1. Publishing with an App Access Token - Facebook Developers
  2. Facebook for Websites - Facebook Developers
  3. Like - Facebook Developers
  4. Open Graph Overview - Facebook Developers
5ervant
  • 3,928
  • 6
  • 34
  • 63
  • This in no way answers the poster's question. – Troy Alford Apr 29 '13 at 20:15
  • 2
    Because the OP is clearly asking how to find out information about the usage of an existing page. Your answer asks him to create a social network of his own, get people to sign up for it, then do some kind of analytics on it. That isn't even related to the *topic* he's discussing - which revolves around *no-impact metric gathering* - not how to track sign-ups. – Troy Alford Apr 29 '13 at 20:21
  • Yes - but read his edit. I think you're replying to the initial question - in which the OP makes it sound like this is on his own page. I'll undo my downvote based on that. Your answer doesn't apply based on the *edited* version. – Troy Alford Apr 29 '13 at 20:27
  • @TroyAlford Okay, I'll try to explain a little bit, if a visitor registered on the mentioned network, all of the URLs will automatically added some QUERY STRING base on their username, and when they now share any URL on the site and when that shared URL got visit, it will recorded on the database. *(Did you see that? That is a possible way because the question is quite impossible!)* But you could still check the links that mentioned on the answer if it's possible.. – 5ervant Apr 29 '13 at 20:38