To get the most benefit from this presentation, it is recommended that you work through the two examples below either during or after the session. To run through them, you'll need the following programs installed. They are all FREE. If you are ever asked for a credit card number, you've gone the wrong way. I will be using a Windows machine, but I believe this should work just the same on Mac. It is recommended you install them in this order:
- The R Project for Statistical Computing
- RStudio Desktop
- Once R and RStudio Desktop are installed, open RStudio and copy-paste the following commands in the window labeled Console. It will probably take a few minutes if you're installing R for the first time:
- install.packages("Rfacebook")
- install.packages("twitteR")
You can also find all of the R code used in this workshop in these two files. First, code to download data from Facebook:
# Tutorial/Demonstration of Facebook Data Calls using R
# by: Richard N Landers (rnlanders@tntlab.org)
#
# We'll be grabbing some public posts from Facebook from a Page of interest
# Open Facebook retrieval library
library(Rfacebook)
# At this point, go grab an API access token from the Graph API Explorer
# Go to https://developers.facebook.com/tools/explorer/ and click "Get Token"
# Store this value in the next variable
token <- "xxxxxxxx"
# Grab public group or page names so that you can determine Facebook's ID number for
# the group you actually want to grab data from (must be OPEN)
ids <- searchPages("odu business", token=token)
# Next we'll grab the last 200 posts; note that these are downloaded 25 at a time
group <- getGroup(group_id=1598275587141066, token=token, n = 200)
Second, code to download data from Twitter:
# Tutorial/Demonstration of Twitter Data Calls using R
# by: Richard N Landers (rnlanders@tntlab.org)
#
# We'll be grabbing the most recent public posts on #business from Twitter
# Open Facebook retrieval library
library(twitteR)
# At this point, create an "App" on Twitter after logging in by going to
# http://apps.twitter.com and "creating an application"
# Once you've created an application, open its settings, go to Keys and Access Tokens,
# generate, then copy/paste the four strings required here
consumer_key <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
consumer_secret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
access_token <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
access_secret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
# Let's grab all recent Twitter posts about #business that we can and convert to a data frame
busiSearch <- searchTwitter("#business", n=200)
busiSearch_df <- twListToDF(busiSearch)
Finally, you can download the slides from this presentation here: