Download your Facebook photos using R

So tonight I wanted to download all my Facebook pictures. For some reason the zip file was corrupted each of the 3 times I downloaded, so I remembered that some time ago I was playing around with an R project named Facebook Data-Mining. The project is conveniently located at github and you can access it here. Looking at the  project description you realize that you can do much more with the project.

First of all you need an Access Token that you can get from https://developers.facebook.com/tools/explorer. After you get it navigate to the AccessToken.R file.Copy and paste the following as I added here the Facebook ID definition

# Get a Facebook Graph API Explorer Access Token
# Go to 'https://developers.facebook.com/tools/explorer', 
# login and click "Get access token"
# Your ID is located first in the output of the Graph Explorer,it's all numbers
# Store your access token here:

me <- "PasteYourFacebookIDHere"
access.token <- "PasteYourAccessTokenHere"

 Now go and source the Setup.R script

# Step 1: Create functions used by the demo
# This creates the 'facebook' function as described at
# http://romainfrancois.blog.free.fr/index.php?post/2012/01/15/Crawling-facebook-with-R
# and other functions to create initials, etc.
cat("Step 1: Create functions used by the demo","\n")
source("Functions.R")

# Step 2: Run the requirements script
# This installs (if required) and loads the mandatory libaries
cat("Step 2: Run the requirements script","\n")
source("Requirements.R")

Finally, run the following excerpt from the Photos.R script

# Create a "photos" directory (Warnings ignored so if it 
# already exists it will safely continue)

# Create a "photos" directory or call it as you like it
dir.create( "photos", showWarnings = FALSE )

# Create a directory for the individual's photos
dir.create( paste("photos",individual.id, sep="/"), showWarnings = FALSE )

# Download each of the individuals photos
for (i in 1:length(individual.photos.url)) {
download.file(individual.photos.url[i], individual.photos.file[i])
}

Then R will output a bunch of download streams, like this and inside the working directory you will find a photos folder and a Facebook subfolder

Note : It is likely that you will get the known error when a connection to Facebook via R is made

Error in function (type, msg, asError = TRUE)  : 
  SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

The solutions to this are outlined in the A tiny RCurl headache post.



Comments

    1. Thanx! You were well ahead on Facebook calls before I ever noticed the need for an API call

  1. David Walker says:

    The original code is here:
    https://github.com/datamgmt/facebook-data-mining

    The original blog post about it is here:
    http://datamgmt.com/an-introduction-to-social-network-data/

    The original presentation is here:
    http://www.scribd.com/doc/96145329/An-Introduction-to-Social-Network-Data

    Ihope that you find them all useful

  2. “Error in function (type, msg, asError = TRUE) :
    SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”

    Error found could you direct me to a site to resolve this.

    Thanks in advance!

    1. You can use tha method that I outline in the A tiny RCurl headache post.

  3. Laszlo Zsurzsa says:

    Everything is working but i get low quality photos at download. (I wanted to download my photos) What could be the problem?