Connect to the Facebook API with R for Windows Users
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="http://curl.haxx.se/ca/cacert.pem", 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="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
# http://romainfrancois.blog.free.fr/index.php?post/2012/01/15/Crawling-facebook-with-R
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( "https://graph.facebook.com/%s%s&access_token=%s", path, options, access_token ), cainfo="cacert.pem" )
fromJSON( data )
}
R-bloggers.com 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.