Getting a developer Twitter account First of all you must go to Twitter Developers page and sign up for a new account,
Getting a curl CertificationOpen your R console and start by loading the following libraries # # Clear the previously used libraries # > rm(list=ls()) # # Load the required R libraries # > library(twitteR) > library(ROAuth) > library(RCurl) > download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem") Setting the Certification at Twitter We will prepare the call to function OAuthFactory to get the auth object. # # Set constant requestURL # > requestURL <- "https://api.twitter.com/oauth/request_token"
> authURL <- "https://api.twitter.com/oauth/authorize" In consumerKey field paste the access token you got from your twitter developer application. > consumerKey <- "xxxxxxxxxxxxxxxxxx" In consumerSecret field paste the access token you got from your twitter developer application. > consumerSecret <- "xxxxxxxxxxxxxxxxxx"Creating the authorization object by calling function OAuthFactory > twitCred <- OAuthFactory$new(consumerKey=consumerKey, consumerSecret=consumerSecret, requestURL=requestURL, accessURL=accessURL, authURL=authURL) At this point we are ready to ask for our credentials to Twitter. Let's go for it ! | # Asking for access > twitCred$handshake(cainfo="cacert.pem") In your R console you will see the following message instructing you to direct your web browser to the specified URL. There you will get a PIN code which you will have to type in your R console. To enable the connection, please direct your web browser to: https://api.twitter.com/oauth/authorize?oauth_token=xxxx When complete, record the PIN given to you and provide it here: xxxxxx Perfect ! Almost done. Just verify that your new credential is working properly > registerTwitterOAuth(twitCred) [1] TRUE And save it for future use by downloading a Cred file at your default R folder > save(list="twitCred", file="twitteR_credentials") Done ! Start searching TwitterNow its time to use it. To do so, imagine you open your R console from scratch, nothing loaded in memory. We assume that you have placed at your R default console, files "cacert.perm" and "twitteR_credentials" > library (twitteR) > load("twitteR_credentials") > registerTwitterOAuth(twitCred) Get, for instance, tweets about United Airlines s <- searchTwitter('#United', cainfo="cacert.pem") Watch out ! When searching, do not forget using your CA Cert, otherwise you will get the following horrible error message. [1] "SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" Error en twInterfaceObj$doAPICall(cmd, params, "GET", ...) : Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed |\____/| ___________ / @ @ \ / ( > º < ) < use it gently ! `>>x<<´ \___________ / O \ You can post any comment about this article at cRomoData.com |
Data Mining with R > Mining Twitter >