Manipulate facebook data with R

If you need to extract useful information on social network website, this post is for you.
I'll tell you my attempt to extract meaningful information from facebook using R and the facebook API.

Sign in with the facebook developper interface

First of all, you need to sign in to the facebook developer interface to access the graph API.

The Graph API is the primary way to get data in and out of Facebook's social graph. It's a low-level HTTP-based API that you can use to query data, post new stories, upload photos and a variety of other tasks that an app might need to do

Create an app

Second, you will need to create an application to extract these information.

On the right side of the screen, click on the green Create New app button:


After the app has been created:

  1. Go to settings and fill inContact Email
  2. Add aplatform and select Website
  3. Fill in the Site url with http://localhost:1410/ then save changes.

To finalize your settings, pick up the app Id and app secret from the app dashboard then paste them into your R script:

fbOAuth(app_id="your app id here", 
                               app_secret="your app secret here", 
                               extended_permissions = TRUE)

Note that you will need to install and load the Rfacebook package as It provides a bunch of useful functions to facilitate interaction with the facebook API.

Now your R script is able to communicate with the Graph API of facebook.

Case study

I started with a project that extract all public posts mentionning some of the most known Malagasy politicians then put them into a datatable, posters and their profile pictures are also displayed.

Enjoy!