March 13, 2014

Rfacebook with OAuth

Today I attempted to get information from Facebook API using OAuth. With OAuth, you can get more private information, e.g. likes, check-ins. Before getting the OAuth authentification for your Facebook application (i.e. Rfacebook), you have to register for one. Please visit the page, and get your App ID and App Secret. With this information, you can use the fbOAuth function. Execute it, then you will be required to add the URL of the local host. This step is a little bit complicated, so see this page. Were you successful ? If so, I recommend you save your OAuth to a local file. Okay, it's all done! You can now get various types of information from Facebook!

Notice:If your connection is freezed to use fbOAuth, I highly recommend you update your httr package. It seems that Old version of it doesn't work.

Now, Here's the result. I get the information of Checkin and visualize it as a Map. Hmm… Checkin data of my friends seems to concentrate on Tokyo.

fb_oauth <- fbOAuth(app_id="XXXXXXXXXXX",
save(fb_oauth, file="fb_oauth")
my_friends <- getFriends(token=fb_oauth, simplify=TRUE)
my_friends_info <- getUsers(my_friends$id, token=fb_oauth, private_info=TRUE)
checkin <-"rbind", 
                          function(x)getCheckins(x, n=10000, token=fb_oauth
# visualize
map <- Leaflet$new()
map$setView(c(checkin$place_lat[10], checkin$place_long[10]), zoom = 8)
for(i in seq_len(nrow(checkin))){
    c(checkin$place_lat[i], checkin$place_long[i]),
    bindPopup = checkin$place_name[i]

No comments:

Post a Comment