Victor Gau
Lightning Talk @ Kaohsiung useR! Meetup
2014/05/05
Outline
 What is the Social Graph?
 Graph API Explained
 What is JSON?
 “R” to Parse JSON
 Spider Revisited
 “R” to ...
What is the Social Graph?
Business Insider: So What The Heck Is The 'Social Graph'
Facebook Keeps Talking About?
Graph API Explained
 APIs for accessing social graph
 HTTP requests are sent to access the social
graph (the responses a...
Graph API Explained
https://www.facebook.com/HTC
Graph API Explained
https://graph.facebook.com/HTC
What is JSON?
 JavaScript Object Notation
 http://en.wikipedia.org/wiki/JSON
“R” to Parse JSON
 Install “rjson” package
 install.packages(“rjson”)
 Load “rjson” package
 library(rjson)
 Function...
Sample Code - Reading JSON
data = '{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"height_cm": 16...
Spider Revisited
# Load Required Packages
library(RCurl)
library(XML)
# Get Page Source
html = getURL("http://www.ptt.cc/b...
“R” to Access the Social Graph
# Load Required Packages
library(RCurl)
library(rjson)
# Retrieve Data (in JSON format)
dat...
“R” to Access Social Graph
 Access Token would be needed for
certain content in social graph most of
the time.
 Access T...
Using Facebook Developer Tools
https://developers.facebook.com/tools/
Topics for Sharing Next time
 Authentication
 Social Plugins
 Open Graph Protocol
 FBML
 XFBML
 FQL
 …
20140505 - Victor Gau - R to access the social graph from facebook
20140505 - Victor Gau - R to access the social graph from facebook
Upcoming SlideShare
Loading in …5
×

20140505 - Victor Gau - R to access the social graph from facebook

1,122 views

Published on

Some basic concepts of using R to access the social graph from the Facebook.

Published in: Data & Analytics, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,122
On SlideShare
0
From Embeds
0
Number of Embeds
342
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

20140505 - Victor Gau - R to access the social graph from facebook

  1. 1. Victor Gau Lightning Talk @ Kaohsiung useR! Meetup 2014/05/05
  2. 2. Outline  What is the Social Graph?  Graph API Explained  What is JSON?  “R” to Parse JSON  Spider Revisited  “R” to Access the Social Graph  Using Facebook Developer Tools  Topics for Sharing Next Time
  3. 3. What is the Social Graph? Business Insider: So What The Heck Is The 'Social Graph' Facebook Keeps Talking About?
  4. 4. Graph API Explained  APIs for accessing social graph  HTTP requests are sent to access the social graph (the responses are in JSON format)  most requests are sent to https://graph.facebook.com  requests for videos are sent to https://graph- video.facebook.com  https://developers.facebook.com/docs/gr aph-api/quickstart/v2.0
  5. 5. Graph API Explained https://www.facebook.com/HTC
  6. 6. Graph API Explained https://graph.facebook.com/HTC
  7. 7. What is JSON?  JavaScript Object Notation  http://en.wikipedia.org/wiki/JSON
  8. 8. “R” to Parse JSON  Install “rjson” package  install.packages(“rjson”)  Load “rjson” package  library(rjson)  Functions to use:  fromJSON()  toJSON()  newJSONParser()
  9. 9. Sample Code - Reading JSON data = '{ "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 25, "height_cm": 167.64, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100" }, "phoneNumbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }' person <- fromJSON(data) person$firstName person$lastName
  10. 10. Spider Revisited # Load Required Packages library(RCurl) library(XML) # Get Page Source html = getURL("http://www.ptt.cc/bbs/R_Language/index.html") # Parse to get information using XPath xml = htmlParse(html) Xpath = "//div[@class='title']/a//text()" titles = xml [Xpath]
  11. 11. “R” to Access the Social Graph # Load Required Packages library(RCurl) library(rjson) # Retrieve Data (in JSON format) data = getURL("https://graph.facebook.com/htc", ssl.verifypeer = FALSE ) # Read JSON htc <- fromJSON(data)
  12. 12. “R” to Access Social Graph  Access Token would be needed for certain content in social graph most of the time.  Access Token can be retrieved by using graph explorer from Facebook Developer Tools.  Sample URL for retrieving information with Access Token:  http://graph.facebook.com/me/friends?acce ss_token=XDFAFDFXXXXXXXDAFDA
  13. 13. Using Facebook Developer Tools https://developers.facebook.com/tools/
  14. 14. Topics for Sharing Next time  Authentication  Social Plugins  Open Graph Protocol  FBML  XFBML  FQL  …

×