Thursday, October 16, 2014

Playing with the Facebook Graph API in Python: Downloading posts from "The Elbi Files" Page

If you are a fan of The Elbi Files, you can download the posts on the page using the procedure described here. I am using Ubuntu 12.04.

  1. Install pip[1].
  2. Configure and activate facebookenv virtual environment[2].
  3. Install requests package while in facebookenv environment: pip install requests
  4. Get an access token using Facebook's Graph API Explorer tool[3].
  5. Download the Python file below. Make sure you change the access token to the  one you obtained from step 4.
  6. Run the script on the terminal and redirect the output to a file:  PYTHONIOENCODING=UTF-8 python elbifiles.py > elbifiles.txt
  7. Note that the script downloads the messages only. Facebook however allows you to download more! Use responsibly. Now do some "interesting" text processing on the text file!


Resources:
[1] http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/
[2] http://facebook-sdk.readthedocs.org/en/latest/install.html
[3] https://developers.facebook.com/tools/explorer

1 comments:

neilmarion said...

I'm pretty sure there are Python libraries that automatically generates your fb access token just by giving it, as parameters, your app id and app secret. Rather than copy-pasting from the api explorer. But first create your facebook app (https://developers.facebook.com/) :P