Saturday, 2 May 2015

Getting Started with Graph API

In order to get familiar with Facebook's Graph API , i'll write a simple python program that provides the user with the functionality of searching for a particular friend in his/her friends list and displaying some basic details about the friend.

So, Let's get started.

First install the facebook graph API for python from here.
Now, before making any calls to the graph API , I need an access token. In my case I think I need a user access token because my program needs to read my facebook data on my behalf.
So, I will generate the token manually from the facebook graph API gui and select the permissions that I need.

Now, following this excellent tutorial , I make the graph object using my access token.

Replace my_token with the token generated in previous step.
In the tutorial they also gave a version attribute to the facebook.GraphAPI call but when I did that , it gave me an error: 'unexpected keyword argument 'version'', so I decided to remove it and now it seems to work fine.

Let's try to get a list of all my friends:

for friend in friends['data']:
    print friend['name']

So, this only gives the name of my friends who have used the graphAPI before.
But how can I get a list of all my friends?
Searching around a bit[1][2][3] led me to the conclusion that I can't get the list of all my friends using GraphAPI v2.0.
Well this was disappointing.
If I can't even get a list of my friends using the graphAPI , I wonder how useful the graphAPI really is?

1 comment:

Math of Intelligence : Logistic Regression

Logistic Regression Logistic Regression ¶ Some javascript to enable auto numberi...