library(twitteR)
Set up a twitter
app at https://dev.twitter.com/apps
Fill in all the pertinent information.
To get OAuth tokens, go to Test OAuth
, and it will show you the consumer key
and consumer secret
. I stored these in a folder that is not part of the package, in keys/tokent.txt
and keys/secret.txt
, respectively.
requestURL <- "https://api.twitter.com/oauth/request_token" accessURL <- "https://api.twitter.com/oauth/access_token" authURL <- "https://api.twitter.com/oauth/authorize" token <- scan("keys/twitterToken.txt", what="character", n=1) secret <- scan("keys/twitterSecret.txt", what="character", n=1) twitterCredentials <- OAuthFactory$new(consumerKey=token, consumerSecret=secret, requestURL=requestURL, accessURL=accessURL, authURL=authURL) twitterCredentials$handshake() registerTwitterOAuth(twitterCredentials) testTweets <- homeTimeline() save(twitterCredentials, file="keys/twitteRCredentials.RData") # saves for further use
Note that we have saved the credentials to a file that again is not part of the package. If we want to use our credentials later, we simply re-load them.
load("keys/twitteRCredentials.RData") registerTwitterOAuth(twitterCredentials) testTweets <- homeTimeline()
Set up a Facebook app at https://developers.facebook.com/apps. Fill in the information.
Again, I have the ID and secret in text files that are not part of the package. During authorization, you will need to go into your Facebook app,
install.packages("Rfacebook") install.packages("Rook") library(Rfacebook) appID <- scan("keys/facebookID.txt", what="character", n=1) appSecret <- scan("keys/facebookSecret.txt", what="character", n=1)
Under Settings
-> Basic
-> Add Platform
, select Website
, and put in the web address that was supplied above (mine was http://localhost:1410/), and hit enter to continue.
fbAuth <- fbOAuth(app_id=appID, app_secret=appSecret) save(fbAuth, file="keys/facebookCredentials.RData")
load("keys/facebookCredentials.RData") me <- getUsers("me", token=fbAuth) me news <- getNewsfeed(fbAuth)
If you get an SSL certification error, then you should run:
library(RCurl) # Set SSL certs globally options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.