110 likes | 122 Views
Learn how to access the Twitter API, extract data, clean and preprocess it, perform data modeling, frequency analysis, clustering, segmentations, and visualize results using R programming.
E N D
R Programming Social Media Mining Module: Accessing an API
Social Media Mining Module • Accessing an API • Extracting Data • Cleaning and PreProcessing • Data Modeling • Frequency analysis • Clustering • Segmentations • Result Visualizations
SMMM: Accessing an API API = Application Program(ming) Interface An application program interface (API) is code that allows two software programs to communicate with each other.
SMMM: Accessing the Twitter API STEP 1: Create a Twitter account STEP 2: Install a bunch of packages (see code). STEP 3: Go to: https://apps.twitter.com/app/new
SMMM: Accessing the Twitter API STEP 4: Obtain your keys and your tokens. You will need four pieces of information to connect to the Twitter API – • Customer API Key • Customer API Secret • Access Token • Token Secret Note that these are UNIQUE to you and TEMPORARY.
SMMM: Accessing the Twitter API STEP 5: Establish the connection and then create the “handshake”. reqURL <- "https://api.twitter.com/oauth/request_token" accessURL <- "https://api.twitter.com/oauth/access_token" authURL <- "https://api.twitter.com/oauth/authorize" twitCred <- OAuthFactory$new (consumerKey=consumerKey, consumerSecret=consumerSecret, requestURL=reqURL, accessURL=accessURL,authURL=authURL) twitCred$handshake(cainfo = system.file("CurlSSL","cacert.pem", package = "RCurl")) STEP 6: The “handshake” will generate a unique PIN that you will have to paste into your console.
SMMM: Accessing an API Once you establish the handshake, you are ready to start scraping! You can scrape “real time” using FilterStream or you can scrape retroactively using SearchTwitter.