Connect to the Facebook API with R for Windows Users

[This article was first published on Data Twirling » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Recently there have been some great posts that highlight how easy it is to hook into the Facebook Graph API using R. Crawling Facebook with R started the discussion and Apply R highlighted how easy it was to plot our network.

In order to replicate the examples on Windows, most likely you will need to run a few extra lines of code before calling the API. Keep this code handy if you want to hook into Twitter or Google Analytics as well.

# download the file needed for authentication download.file(url="", destfile="cacert.pem") # set the curl options curl <- getCurlHandle() options(RCurlOptions = list(capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE)) curlSetOpt(.opts = list(proxy = 'proxyserver:port'), curl = curl)

From here, you should be able to follow along with the code samples. Hope this helps.

UPDATE: It is worth noting that you can tweak the Facebook function as well to include cacert.pem in the getURL call, eliminating the need to set curl options.

download.file(url="", destfile="cacert.pem") # facebook <- function( path = "me", access_token = token, options){ if( !missing(options) ){ options <- sprintf( "?%s", paste( names(options), "=", unlist(options), collapse = "&", sep = "" ) ) } else { options <- "" } data <- getURL( sprintf( "", path, options, access_token ), cainfo="cacert.pem" ) fromJSON( data ) }

To leave a comment for the author, please follow the link and comment on their blog: Data Twirling » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)