twitter authentication with R

Do you have any questions about this tutorial? Feel free to open up a topic in the forum:

http://thinktostart.com/forums/forum/questions-tutorials/twitter-authentication-r/

 

This article is just a small summary about the authentication process with Twitter. Its about creating the Twitter app and doing the handshake cause you have to do it every time you want to get data from Twitter with R.

Since Twitter released the Version 1.1 of their API a OAuth handshake is necessary for every request you do. So we have to verify our app.

First we need to create an app at Twitter.

Got to https://dev.twitter.com/ and log in with your Twitter Account.

Now you can see your Profile picture in the upper right corner and a drop-down menu. In this menu you can find “My Applications”.

Click on it and then on “Create new application”.

You can name your Application whatever you want and also set Description on whatever you want. Twitter requires a valid URL for the website, you can just type in http://test.de/ ; you won´t need it anymore.

And just leave the Callback URL blank.

3

Click on Create you´ll get redirected to a screen with all the OAuth setting of your new App. Just leave this window in the background; we´ll need it later

Before we go on, make sure you have installed the newest version of the twitteR package from github.

Therefore you can use the following code:

Now the twitteR package is up-to-date and we can use the new and very easy setup_twitter_oauth() function which uses the httr package.

 

Twitter Authentication with R:

First you have to get your api_key and your api_secret as well as your access_token and access_token_secret from your app settings on Twitter. Just click on the “API key” tab to see them.

And that´s it.

If you want to test your authentication just try to get some tweets with:

 

Now you can continue your Twitter research with one of my Twitter examples:

Twitter Tutorials

Or follow me on Twitter to stay up-to-date about everything connected to R and Data Science

 

SHARE
Previous articleSentiment Analysis on Twitter
Next articleCreate a wordcloud with Twitter Data and R
During my time at university and learning about the basics of economics I started heavily exploring the possibilities and changes caused by digital disruptions and the process of digital transformation, whereby I focused on the importance of data and data analytics and combination with marketing and management. My personal focus of interest lies heavily on technology, digital marketing and data analytics. I made early acquaintance with programming and digital technology and never stop being interested in following the newest innovations. I am an open, communicative and curious person. I enjoy writing, blogging and speaking about technology.

179 COMMENTS

  1. Hi there!
    I can’t get the authentification working:

    Error in get(name, envir = asNamespace(pkg), inherits = FALSE) :
    object ‘.setDummyField’ not found

    Do u know what the problem could be?

    Thanks a lot!
    Jessica

    • Hey Jessica!
      Nice to see you on my blog!
      Did you try to reset your workspace and start with a clean one?
      And did you load all the newest versions of the required packages?
      I would like to get some more info about your problem :) Maybe it would help if you post your R code. Maybe we can find a mistake

    • Ok I hope I get it now:
      You define the variables in the beginning and then type:

      twitCred <- OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=reqURL,accessURL=accessURL,authURL=authURL)

      And then this error appears?
      Then you should update your R to the newest version. Maybe the twitteR package doesn't work very well with your R version

  2. oh boy.. why isn’t this showing my code?

    after cred=

    OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=requestURL,accessURL=accessURL,authURL=authURL)

    then error…

  3. the update to 3.0.1 and authorization finally worked
    when i searched Twitter the following happened:

    [1] “SSL certificate problem, verify that the CA cert is OK. Details:nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”
    Error in 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

    I did solve it via:

    library(RCurl)
    options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))

    And now i get my tweets just fine :-)
    Thanks for ur help!

      • jap, i’m using windows 😉
        I just restarted R. Am I supposed to go through the authorization process everytime I restart?

  4. Another thing I couldn’t fix so far:

    Warning message: In doRppAPICall(“search/tweets”, n, params = params, retryOnRateLimit = retryOnRateLimit, : 100 tweets were requested but the API can only return 26

    I tried to get tweets from a certain time periode and it wouldn’t give me any results back. Then I tried without a time frame and even then R only returned a few.

    Have u come across that?

    • Yeah this is a problem with the new Twitter API. You just got 26 Tweets because Twitter only provided 26. They set a time period and just within this period you can receive the tweets. So now chance till now to get 1 year old tweets or so with the search twitter method

  5. Hello there,
    Am using R v3.0.1 and I get this error
    Error in function (type, msg, asError = TRUE) :
    SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
    What could I do??

  6. Yes am using Windows. . .
    I got the PIN and entered now in R.
    Then when I searchTwitter i get the error
    >>This is my code

    tweets = searchTwitter(“#analytics”, n=1000)
    [1] “SSL certificate problem, verify that the CA cert is OK. Details:nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”
    Error in 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

  7. Jessica in the previous post said that she fixed using :

    library(RCurl)
    options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))

    But i get the error as:

    >> the code:

    > library(RCurl)
    > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))
    Error: unexpected input in “options(RCurlOptions = list(cainfo = system.file(“”

  8. Sorry am new to “R”
    Now I just typed out everything and I get:
    >>

    > tweets = searchTwitter(“#analytics”,n=1000,cainfo=”cacert.pem”)
    [1] “Unauthorized”
    Error in twInterfaceObj$doAPICall(cmd, params, “GET”, …) :
    Error: Unauthorized
    >

    • Ok now we got a step further;) It says that you are unauthorized to use the GET method of twitter. So there was something wrong in the authentification process. Please type it in line by line. The whole authentification process has to be done every single time you start R. So restart R, go through the auth process and then you can use searchTwitter

  9. Thank you so mush. . I have been working on this for a whole week and got into this blog.
    It’s really helpful man.
    If i get into some problems, I’ll ask you. . .

  10. Man. . Am tired of this. .I restarted everthing and typed all the code, yet Again I get this error. . .

    library(twitteR)
    > library(ROAuth)
    > reqURL accessURL authURL consumerKey consumerSecret twitCred twitCred$handshake()
    Error in function (type, msg, asError = TRUE) :
    SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
    >

  11. I need help. . We gone a step further man. .
    When am trying to analyze I get this. . . .

    >analysis = score.sentiment(tweets.text, pos.words, neg.words)
    Error in match(words, exc.words) :
    argument “exc.words” is missing, with no default

  12. K man. .Here is all my codes. .

    library(twitteR)
    > library(ROAuth)
    > reqURL accessURL authURL consumerKey consumerSecret twitCred twitCred$handshake()
    > library(RCurl)
    > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”,”cacert.pem”,package=”RCurl”)))
    > twitCred$handshake()
    To enable the connection, please direct your web browser to:
    http://api.twitter.com/oauth/authorize?oauth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    When complete, record the PIN given to you and provide it here: xxxxxxx
    > local({pkg library(plyr)
    > tweets = searchTwitter(“#Analytics”,n=1000,cainfo=”cacert.pem”)
    > length(tweets)
    [1] 1000
    > tweets.text = laply(tweets, function(t)t$getText())
    > pos = scan(‘positive-words.txt’, what=’character’, comment.char=';’)
    Read 2006 items
    > neg = scan(‘negative-words.txt’, what=’character’, comment.char=';’)
    Read 4783 items
    > source(‘sentiment.r’)
    > analysis = score.sentiment(tweets.text, pos.words, neg.words)
    Loading required package: stringr
    Error in FUN(X[[1L]], …) : could not find function “str_split”
    In addition: Warning message:
    In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
    there is no package called ‘stringr’
    > utils:::menuInstallPkgs()
    — Please select a CRAN mirror for use in this session —
    trying URL ‘http://cran.rstudio.com/bin/windows/contrib/3.0/stringr_0.6.2.zip’
    Content type ‘application/zip’ length 75189 bytes (73 Kb)
    opened URL
    downloaded 73 Kb

    package ‘stringr’ successfully unpacked and MD5 sums checked

    The downloaded binary packages are in
    C:UsersTwisterAppDataLocalTempRtmpmCFsdWdownloaded_packages
    > library(stringr)
    > analysis = score.sentiment(tweets.text, pos.words, neg.words)
    Error in match(words, exc.words) :
    argument “exc.words” is missing, with no default
    > q()
    > analysis = score.sentiment(tweets.text, pos.words, neg.words)
    Error in match(words, exc.words) :
    argument “exc.words” is missing, with no default
    > save.image(“C:\Users\Twister\Desktop\Project things\TwitteR\Inital codings”)
    > analysis = score.sentiment(tweets.text, pos.words, neg.words)
    Error in match(words, exc.words) :
    argument “exc.words” is missing, with no default

  13. Man,
    Can I get the Positive, Negative tweets in to some kinda Document format. .so that i could know what is negatively spoken . . . .

      • Thanks man,
        What is the type of algorithm used?? Is it SVM, NB etc..
        Whats the accuracy level for this analysis??
        If there is a tweet as “This product is not good”, then it will be considered as positive sentiment. . .So what to do for it??

        • There is no real algorithm in this example because it´s a very basic one. You just get the tweets and match the containing words with a list of positive and negative words.
          But i´m thinking about writing another sentiment analysis post which uses the viralheat sentiment API as it is fully compatible with R (https://app.viralheat.com/developer/sentiment_api).
          This should deliver more accurate results than the easy wordlist method.

  14. Hi.

    I am getting this error when I am trying to execute the steps mentioned above. Could you please tell me if I am missing something. I am really new to using R

    Error in registerTwitterOAuth(twitCred) :
    oauth has not completed its handshake

    • Hi,
      in this example you don´t get any tweets from twitter. You just connect to twitter.
      If you want to search twitter you have to use:
      tweets = searchTwitter(“keyword_you_search_for”, n=200, cainfo=”cacert.pem”)

      After that you can just write “tweets” in your R console and all the downloaded tweets are displayed

  15. Hi Julian, I am getting a strange issue with twitteR …

    When I try to do the handshake, the prompt to get the PIN is not waiting enough to get the pin … after couple of seconds, it says “Error: Unauthorized”. I have pasted the session info in the end.

    credential <- OAuthFactory$new(consumerKey="key",consumerSecret="key",requestURL="https://api.twitter.com/oauth/request_token&quot; ,accessURL="https://api.twitter.com/oauth/access_token&quot;,authURL="https://api.twitter.com/oauth/authorize&quot;);

    credential$handshake(cainfo="cacert.pem")

    To enable the connection, please direct your web browser to:
    https://api.twitter.com/oauth/authorize?oauth_token=a8fLZZmWR2NnAtnL9uYlVZf11ntaKrO1SvNJmrzkPwg
    When complete, record the PIN given to you and provide it here:
    Error: Unauthorized

    Session Info:
    R version 3.0.1 (2013-05-16)
    Platform: x86_64-w64-mingw32/x64 (64-bit)

    locale:
    [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
    [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
    [5] LC_TIME=English_United Kingdom.1252

    attached base packages:
    [1] stats graphics grDevices utils datasets methods base

    other attached packages:
    [1] twitteR_1.1.7 rjson_0.2.12 ROAuth_0.9.3 digest_0.6.3 RJSONIO_1.0-3 RCurl_1.95-4.1
    [7] bitops_1.0-5

    loaded via a namespace (and not attached):
    [1] tools_3.0.1

  16. Hey there. . . .Do you have any tutorials regarding ARIMA in R. . .And is it worth to predict the future values using ARIMA??? Am actually doing a project regarding it. . .

  17. When we use the command:
    >SearchTwitter(“#Keyword”,n=1500)
    So, n=1500 is what kind of sampling method.
    And the second query is can we use combination of words like “#HCL salary” like wise. .So how can I do that…

    • Hey Deepak raj
      SearchTwitter gets real-time tweets. So you get the 1500 newest tweets matching your search term. In an upcoming release Twitter will change this to popular tweets. So the API will just release popular tweets by default. But they will publish some information before the release.

      TwitteR is just a parser to translate the R code and call the Twitter API with your parameters. So you just have the option to use one search string. But this search string can contain everything you want. It can contain accounts like “@julianhi” and also hashtags. So your example “#HCL salary” gives you tweets containing the hashtag #HCL and the word salary.
      Hope i could help you

        • Hey!
          The problem in your case is the keyword.
          If you go to the normal twitter website and search for “#hcl salary” there are just something about 5 tweets ever written with these keywords. And the twitteR search which uses the Twitter API can just return recent ones, but the last tweet containing your keywords was written months ago.
          So in other words: there are just no recent tweets containing your keywords

  18. Hello !
    Thanks a lot for this tutorial.
    Simple question : is there any way to move (or backup) the cacert.pem file to use it to avoid doing the handshake each time ?
    For example, I’m actually doing the handshake in a the R terminal, because there is a bug in Rstudio about copy/paste the url (mentionned for example here : http://stackoverflow.com/questions/15958512/invalid-request-token-using-oauth-and-r-is-the-r-code-correct). Is it possible to use in R Studio the cacert.pem file handshaked by the terminal ?

    • Hey Jonathan!
      The handshaked cacert file should be saved on your system. So you just be able to use it with RStudio.
      I also had this problems with RStudio and i´ll take a look at it again. I´ll send you some feedback within the next days

  19. Hi there, Another query:

    I tried something new and and I get lot of errors. Plz help me out in this.

    1)got the tweets about specific keyword and I also copied some of the reviews in websites.
    How could I append it to the tweets and do the same sentiment analysis.

    2)What is the code to copy all the tweets to a file.

    3)can I get the tweets in a file and add those reviews from websites along with it and read the file again in R and do the same sentiment analysis. If Yes, tell me how plz…

  20. Julianhi,
    at first I like to than you for your website. It has been very helpful. My question concerns retrieving tweets. Is it possible to retrieve tweets that were created, let’s say, in the past two years? Not every tweet generated but for a certain keyword, e.g., “Samsung”.

    • Hey Jani,
      Thanks for your comment.
      But it’s not possible to get tweets older than let’s say 3 months via the Twitter API. That’s caused by Twitter’s restrictions. You can just get these Tweets from an official Twitter Data Reseller with full firehose access like GNIP. But these services are very expensive.
      I hope I could help you.

  21. hi,
    i’m a fresher with R. thanks for your guidance
    i got a ‘ true’ after complete your code , but I cannot search tweets…

    “SSL certificate problem, verify that the CA cert is OK. Details:nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”
    Error in 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

    wats the problem?

      • Hi julianhi
        compliments for your work and blog. I’m italian so I do not speak English very well, so sorry in advance. I have a problem to complete the authentication phase. Oauth has not completed its handshake because answer: Errore Forbidden. This is my script:
        > require(twitteR)
        >
        > reqURL accessURL authURL consumerKey consumerSecret if (!file.exists(‘cacert.perm’)){
        + download.file(url = ‘http://curl.haxx.se/ca/cacert.pem’,
        + destfile=’cacert.perm’)
        + }
        provo con l’URL ‘http://curl.haxx.se/ca/cacert.pem’
        Content type ‘unknown’ length 241697 bytes (236 Kb)
        URL aperto
        downloaded 236 Kb

        > twitCred curl = getCurlHandle()
        > options(RCurlOptions = list(capath = system.file(‘CurlSSL’, ‘cacert.pem’,
        + package = ‘RCurl’), ssl.verifypeer = FALSE))
        > curlSetOpt(.opts = list(proxy = ‘proxyserver:port’), curl = curl)
        An object of class “CURLHandle”
        Slot “ref”:

        > twitCred$handshake()
        To enable the connection, please direct your web browser to:
        http://api.twitter.com/oauth/authorize?oauth_token=vWwCyCh1sZ8iQyaQEl2nFcV1FUR1JsOrAt0EpXfycUs
        When complete, record the PIN given to you and provide it here: xxxxxxxxxxxxxx
        Errore: Forbidden
        > #verifica
        > registerTwitterOAuth(twitCred)
        Errore in registerTwitterOAuth(twitCred) :
        oauth has not completed its handshake
        >

        I have searched the internet for a solution but nothing. I’m in the stall and I can not go on. You can help me?

        • Hey Claudia,
          Thanks for reaching out and sorry for the late answer. I’ve updated the code and the tutorial and the new code should solve your problem. Let me know if it worked.
          Regards

  22. I am getting error msg after this line… can you please help me find a solution?
    download.file(url= “http://curl.haxx.se/ca/cacert.pem”, destfile = “cacert.pem”)
    Error in download.file(url = “http://curl.haxx.se/ca/cacert.pem”, destfile = “cacert.pem”) :
    cannot open destfile ‘cacert.pem’, reason ‘Permission denied’

  23. i want to code for twitter follower and friend list using R code (output will be get in the form of matrix) .give me guidiance

  24. Hi Julian – I received less errors using this piece of good, but I am still having trouble. You have been really helpful with some of the others on your blog and thought you might spare a minute or two. I can get my PIN but I’m still “Forbidden” – ouch!

    ## Not run:
    > ## A real example, but using a fictitious consumerkey and consumer
    > ## secret – you’ll need to supply your own
    > reqURL accessURL authURL consumerKey consumerSecret twitCred twitCred$handshake()
    To enable the connection, please direct your web browser to:
    http://api.twitter.com/oauth/authorize?oauth_token=Hzn2Sk7ljRTA2rOdBXhJAe0JQscNlY5wCIf6OBkT7M
    When complete, record the PIN given to you and provide it here:

    registerTwitterOAuth(twitCred)
    Error: Forbidden

  25. Hi Julianhi,
    i used the same above code with my consumer key & secert key. Initailly this code was working on my PC but now i am facing an error :Forrbiden.

    reqURL <- "http://api.twitter.com/oauth/request_token&quot;

    accessURL <- "http://api.twitter.com/oauth/access_token&quot;

    authURL <- "http://api.twitter.com/oauth/authorize&quot;

    consKey <- "Myconsumerkey"

    consSecret <- "Mysecrectkey"

    twitCred twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    Error: Forbidden

    Please help me. to resolve it. i need urgently to complete my POC.
    contact me:- vratan009@gmail.com
    vivek

    • Hey Vivek,
      I updated my code just a few days ago, because Twitter changed the API access options.

      But if you use the code above everything should work find. I see you still used the old code.
      Regards

  26. Hi Julian, first of all, thanks so much for this blog and your tutorials, they have been incredibly helpful.

    I followed your instructions using R instead of RStudio since I couldn’t copy the URL there. Everything works fine until I get to the final line of the code. Then I get the error: “oauth has not completed its handshake”.

    The file cacert.pem is in the folder I set as the working directory. I checked the consumer key and secret and updated R and all packages to the latest version.

    I’m really not sure what went wrong. Have you come across this?

    Your help would be very much appreciated. Thanks!

  27. Update: After a bit of ‘trial and error’, I found the solution: In the application settings, I changed the Application Type to “Read, Write and Access direct messages”. Then I had to log out and log in again, and now it works. Just in case anyone else has the same problem. :)

  28. Hi,

    I try to use the presented code, and I can’t complete the handshake. Here is the executed code and the error messages given by R.

    thanks for help, if possible.
    Regards
    FX Jollois

    > # Set SSL certs globally
    > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))
    > # Request token URL https://api.twitter.com/oauth/request_token
    > reqURL # Authorize URL https://api.twitter.com/oauth/authorize
    > authURL # Access token URL https://api.twitter.com/oauth/access_token
    > accessURL # Consumer key
    > consumerKey # Consumer secret
    > consumerSecret twitCred twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    To enable the connection, please direct your web browser to:
    http://api.twitter.com/oauth/authorize?oauth_token=
    When complete, record the PIN given to you and provide it here: …
    Error: Forbidden
    > registerTwitterOAuth(twitCred)
    Error in registerTwitterOAuth(twitCred) :
    oauth has not completed its handshake

    • An other user had a similar problem. Maybe you try his solution:
      “After a bit of ‘trial and error’, I found the solution: In the application settings, I changed the Application Type to “Read, Write and Access direct messages”. Then I had to log out and log in again, and now it works. “

  29. Yes ! I have just remove them to publish the code. And I just see that the message is quietly diffrent from how I write it.

    Regards
    FX Jollois

  30. It is fixed ! I add “s” to “http” and everything works ! I have missed my mistake .

    Thanks for help, and many thanks for the code !
    FX

  31. Hi Julianhi
    I solved it so:
    #load data authentication previously saved
    load(“twitter_authentication.Rdata”)
    library(RCurl)
    curl = getCurlHandle()
    options(RCurlOptions = list(capath = system.file(‘CurlSSL’, ‘cacert.pem’,package = ‘RCurl’), ssl.verifypeer = FALSE))
    curlSetOpt(.opts = list(proxy = ‘proxyserver:port’), curl = curl)
    twitCred$handshake()
    registerTwitterOAuth(twitCred)

    Regards

  32. Hi Julian,

    Clear explanation, as always. I have one problem: when I try to connect, just after I am asked to enter my PIN (but before I have any chance to do so), I receive an “Error: Unauthorized”. I cannot make my head around what could be causing this behaviour. I tested it from different machines and with/without proxy, nothing worked so far.

    I also open a question on Stack Exchange, where I posted the whole code: http://stackoverflow.com/questions/21682266/unauthorized-error-with-twitter-oauth

    • Hey Alessandro,
      this problem often occurs when you enter the whole code at once and hit enter.
      You should run the code line by line. This should solve your problem.
      Please let me know if this worked for you.

      Regards

  33. Hi Julian,

    I am following certain users on twitter as part of my research project.

    I seek to download tweets through R software for the following three scenarios (Assuming user as XYZ)

    1. What XYZ is tweeting?

    2. What people are saying about XYZ on twitter?

    3. What are the tweets made by XYZ that are being retweeted by users?

    For the first scenario, I am make use of the following code:
    rdmTweets.list <- userTimeline('@xyz', n=100, cainfo="cacert.pem")
    Is this the right approach?

    I am making use of following code to download mentions of XYZ on twitter. But the first line also takes into account retweets.
    original.list<-searchTwitter('@xyz',n=1000, cainfo="cacert.pem")
    original.list<-searchTwitter('#xyz',n=1000, cainfo="cacert.pem")

    Kindly comment as to how I can separately download tweets for the above mentioned three scenarios.

    TIA.

    Regards,
    Nikhil.

    • Hey Nikhil,
      sorry for the late answer.

      1.) Yes, this is the right approach to get the users tweets.

      2.) You can find the retweets with the following code. It helps you to find the retweets and then you can delete them from your list.

      # regular expressions to find retweets
      grep(“(RT|via)((?:\b\W*@\w+)+)”, tweets,
      ignore.case=TRUE, value=TRUE)

      # which tweets are retweets
      rt_patterns = grep(“(RT|via)((?:\b\W*@\w+)+)”,
      tweet_txt, ignore.case=TRUE)

      # show retweets (these are the ones we want to delete)
      tweet_txt[rt_patterns]

      I used it in this tutorial:
      http://thinktostart.wordpress.com/2013/06/25/visualize-retweets-with-r/

      3.) When you download the user timeline, you can find the retweet value in the answer. It is an answer
      which tells you how often it was retweeted.
      To find these retweets could be a little bit more difficult.

      I hope I could help you.
      If you have any further questions feel free to ask.

      Regards

  34. Hi Julian,

    I have downloaded twitter data using R in .csv format. These are the fields :

    text favorited favoriteCount replyToSN created truncated replyToSID id replyToUID statusSource screenName retweetCount isRetweet retweeted longitude latitude

    For a given tweet in .csv file, the value of retweetCount>0 though the value for retweeted=0. I am not able to exactly discern the meaning for these three different fields (retweetCount, isRetweet, retweeted).

    Could you please help me understand the same?

    TIA

    • Hey Nikhil,
      So
      retweetCount – How often it was retweeted
      isRetweet – Is this tweet a retweet or an original tweet?
      retweeted – Was the tweet retweeted? (true/false)

      So there seems to be a problem with the API. I don´t really know why it returns these values but I found a lot of similar questions in the Twitter forum but no real answer.
      I will take a look at this topic again.

      Regards

  35. Hi julian
    I am calculating sentiment from twitter tweets.I have a question can we fetch conversations from a single tweet that is fetched in search twitter function.

    • Hey Onkar,
      I think that this is not possible on the direct way. You can just search all the tweets you downloaded for connections. To have access to the whole Twitter data you would need something like a Firehose access.

      Regards

  36. I get the following error by executing : twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)):
    Error in function (type, msg, asError = TRUE) :
    Could not resolve host: api.twitter.com; Host not found, try again

    how to resolve this issue?

  37. Well after I make the authentication and all the necessary, I get this as a result!

    twitterMap(“socialmedia2day”, fileName=”Map_socialmedia2day.pdf”, nMax=3000)
    Getting data from Twitter, this may take a moment.
    Error in twInterfaceObj$doAPICall(paste(“users”, “show”, sep = “/”), params = params, :
    OAuth authentication is required with Twitter’s API v1.1

    Problem on twitter????

    • Hey Tasos,
      it seems like you forgot the last row in the code.
      The authentication is not done after you inserted the PIN. You have to execute the line:
      registerTwitterOAuth(twitCred)
      This line will then, if everything works well, return a “TRUE”.
      Then you are ready to go.

      Regards

  38. Hey Julian!

    Everything works until the point:

    > twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    Error: Unauthorized
    >
    > registerTwitterOAuth(twitCred)
    Error in registerTwitterOAuth(twitCred) :
    oauth has not completed its handshake

    Any idea?

      • Yep, did it line by line, but after running line 14, console says “Error: Unauthorized” :/ The keys are definetely correct (Used Mozilla and my personal Account)

      • same problem, but I use just one twitter account

        R logs

        > library(twitteR,igraph)
        Le chargement a nécessité le package : ROAuth
        Le chargement a nécessité le package : RCurl
        Le chargement a nécessité le package : bitops
        Le chargement a nécessité le package : digest
        Le chargement a nécessité le package : rjson
        > library(RCurl)
        > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))
        > require(twitteR)
        > reqURL accessURL authURL apiKey apiSecret twitCred twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
        Erreur : Unauthorized
        > twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
        Erreur : Unauthorized

        can you help me please ?

  39. library(twitteR)
    library(stringr)
    library(RCurl)

    reqURL <-"https://api.twitter.com/oauth/request_token&quot;
    accessURL <- "http://api.twitter.com/oauth/access_token&quot;
    authURL <- "http://api.twitter.com/oauth/authorize&quot;
    consumerKey="xxxxxxxxxxx" % i have this key
    comsumerSecret="xxxxxxxxxx" % i have this key

    download.file(url="http://curl.haxx.se/ca/cacert.pem&quot;,destfile="cacert.pem") % for what??

    twitCred <- OAuthFactory$new(consumerKey=consumerKey,
    consumerSecret=consumerSecret,
    requestURL=reqURL,
    accessURL=accessURL,
    authURL=authURL)

    twitCred$handshake(cainfo="cacert.pem") # curl is a command line tool for transfering
    registerTwitterOAuth(twitCred)

    Hai julian,

    I wanna ask you several question.

    1. I try to run this code but still error because "unauthorized". i am working with mac os.
    How to solve it?

    2.This code for what?? should i download this file?
    download.file(url="http://curl.haxx.se/ca/cacert.pem&quot;,destfile="cacert.pem")

    3.it there have different setting for the cacert.pem???

  40. Please help!! I am having “unauthorized” when started searching. This problem has been several days. So I decided to create another application today. Could that be my application setting? Below is my R console output:

    > Cred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    To enable the connection, please direct your web browser to:
    https://api.twitter.com/oauth/authorize?oauth_token=YZGu3jRN2ZxG9IwvhvEJMcR9oXTw2GcV8geGp49ME
    When complete, record the PIN given to you and provide it here: 8357550
    > registerTwitterOAuth(Cred)
    [1] TRUE
    > save(Cred, file=”twitter authentication rkresnadi1.Rdata”)
    > twitlst <- searchTwitter("sustainable development", n=1000, cainfo="cacert.pem")
    [1] "Unauthorized"
    Error in twInterfaceObj$doAPICall(cmd, params, "GET", …) :
    Error: Unauthorized

    • Hey Stu,
      your code seems to be ok. I saw that you changes the name of the Credentials Object to Cred, but that shouldn´t be a problem if you did this in your whole code. But you receive a “TRUE” which normally tells you that the authentication was successful. Could you also please post the first part of your code?
      Regards

  41. please why am i getting error: forbidden
    > library(twitteR)
    Loading required package: ROAuth
    Loading required package: RCurl
    Loading required package: bitops
    Loading required package: digest
    Loading required package: rjson
    Warning messages:
    1: package ‘twitteR’ was built under R version 3.0.2
    2: package ‘ROAuth’ was built under R version 3.0.2
    3: package ‘RCurl’ was built under R version 3.0.2
    4: package ‘digest’ was built under R version 3.0.2
    > library(plyr)

    Attaching package: ‘plyr’

    The following object is masked from ‘package:twitteR’:

    id

    Warning message:
    package ‘plyr’ was built under R version 3.0.2
    > library(stringr)
    Warning message:
    package ‘stringr’ was built under R version 3.0.2
    > library(ROAuth)
    > download.file(url=”http://curl.haxx.se/ca/cacert.pem”, destfile=”cacert.pem”)
    trying URL ‘http://curl.haxx.se/ca/cacert.pem’
    Content type ” length 250283 bytes (244 Kb)
    opened URL
    downloaded 244 Kb

    > requestURL accessURL = “http://api.twitter.com/oauth/access_token”
    > authURL consumerKey = “myKey”
    > consumerSecret = “mySecret”
    > Cred Cred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”) )
    Error: Forbidden

    • Hey satya
      The updated code is the code above. But the code used in the question before was an Old version.
      So just use the code from the Tutorial and everything should work.

      Regards

  42. Hi julianhi,

    I’m having the same problem retrieving tweets.

    > tweets = searchTwitter(“sustainable development”, n=200, cainfo=”cacert.pem”)
    [1] “Unauthorized”
    Error in twInterfaceObj$doAPICall(cmd, params, “GET”, …) :
    Error: Unauthorized

    Here is my code, I’m putting it in line by line. Using RStudio Version 0.98.501 on Mac.

    > library(RCurl)
    > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))
    > require(twitteR)
    > reqURL accessURL authURL apiKey apiSecret twitCred twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    To enable the connection, please direct your web browser to:
    https://api.twitter.com/oauth/authorize?oauth_token=KiysFMXkw1ggdHGviVv5U8Yef4ooZxw7AZ89L1LSmFM
    When complete, record the PIN given to you and provide it here: 1234567
    > registerTwitterOAuth(twitCred)
    [1] TRUE
    > tweets = searchTwitter(“sustainable development”, n=200, cainfo=”cacert.pem”)
    [1] “Unauthorized”
    Error in twInterfaceObj$doAPICall(cmd, params, “GET”, …) :
    Error: Unauthorized

    Please help!

    CMG

    • Hi J,

      here’s the complete code, I messed up the last post. Like I said, I’m using RSudio on Mac

      > library(RCurl)
      Loading required package: bitops
      > options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))
      > require(twitteR)
      Loading required package: twitteR
      Loading required package: ROAuth
      Loading required package: digest
      Loading required package: rjson
      > reqURL accessURL authURL apiKey apiSecret twitCred twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
      To enable the connection, please direct your web browser to:
      https://api.twitter.com/oauth/authorize?oauth_token=epAv0cZJWd7sRayMvKwDPVjQtPiVnmX1dK1AKEZjVg
      When complete, record the PIN given to you and provide it here: 1234567
      > registerTwitterOAuth(twitCred)
      [1] TRUE
      > tweets = searchTwitter(“MMR”, n=200, cainfo=”cacert.pem”)
      [1] “Unauthorized”
      Error in twInterfaceObj$doAPICall(cmd, params, “GET”, …) :
      Error: Unauthorized

        • Hey CMG,
          sorry for the late answer but I was very busy.
          I can´t find a bug in your code at the moment.
          But did you try do execute it in the normal R console?
          Sometimes the authentication does not really complete in RStudio.

          Regards

  43. Hello, I am having also the error forbidden during the handshake:

    To enable the connection, please direct your web browser to:
    http://api.twitter.com/oauth/authorize?oauth_token=FWJevpPdDnZrbuqmmkyrQzcUZzRNR3we83LlJdAXnY
    When complete, record the PIN given to you and provide it here: 1817865
    Error: Forbidden

    And I tried many times…..

    here is my code:

    library(twitteR)
    library(RCurl)
    # Set SSL certs globally
    options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))

    require(twitteR)
    reqURL <- "https://api.twitter.com/oauth/request_token&quot;
    accessURL <- "http://api.twitter.com/oauth/access_token&quot;
    authURL <- "http://api.twitter.com/oauth/authorize&quot;
    consumerKey <- "xpArd5lrnnjxxxxxxxxxxxxxxxxxx"
    consumerSecret <- "jFF4fG3wrhx7Ya8P8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    twitCred <- OAuthFactory$new(consumerKey=consumerKey,
    consumerSecret=consumerSecret,
    requestURL=reqURL,
    accessURL=accessURL,
    authURL=authURL)

    twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
    registerTwitterOAuth(twitCred)

    What did I miss ? Do you think SSL is not working properly ?

  44. Good afternoon, I’ve read through the comments and while I saw the same issue (Error: Unauthorized) I didn’t see a way to resolve it.

    > twitCred$handshake(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”))
    To enable the connection, please direct your web browser to:
    https://api.twitter.com/oauth/authorize?oauth_token=xyz
    When complete, record the PIN given to you and provide it here:

    You mention to use the most updated code but I think I am. Here’s what I’m using:

    library(RCurl)
    # Set SSL certs globally
    options(RCurlOptions = list(cainfo = system.file(“CurlSSL”, “cacert.pem”, package = “RCurl”)))

    require(twitteR)
    reqURL <- "https://api.twitter.com/oauth/request_token&quot;
    accessURL <- "https://api.twitter.com/oauth/access_token&quot;
    authURL <- "https://api.twitter.com/oauth/authorize&quot;
    apiKey <- "removed"
    apiSecret <- "removed"

    twitCred <- OAuthFactory$new(consumerKey=apiKey,consumerSecret=apiSecret,requestURL=reqURL,accessURL=accessURL,authURL=authURL)

    twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))

    registerTwitterOAuth(twitCred)

  45. Hi Julianhi i got this error can u help me please?

    Error in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

      • this is my code

        install.packages(c(“devtools”, “rjson”, “bit64″, “httr”))

        #RESTART R session!

        library(devtools)
        install_github(“twitteR”, username=”geoffjentry”)
        library(twitteR)

        api_key <- "mwcOI7mNkPUhxxxxxxxxxxxxxxx"

        api_secret <- "BwyN7OvghbPSW9RDSaSzVu0aRhhxxxxxxxxxxxxxxxxxxxxxxx"

        access_token <- "2829195264-D8HgRXZCyUd193lxxxxxxxxxxxxxxx"

        access_token_secret <- "2829195264-D8HgRXZCyUd193lC5ILEFxxxxxxxxxxxxxxx"

        setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)

        and after setup_twitter_oauth is executed the erros appears

        Error in check_twitter_oauth() : OAuth authentication error:
        This most likely means that you have incorrectly called setup_twitter_oauth()’

        i think httr is 401 but i dont know how to change it

        thanks

  46. i hope you can read my poste.
    I followed the instruction step by step, and I still have this problem: ( Erreur : Authorization Required twitter )

    my code is :

    requestURL<- "https://api.twitter.com/oauth/request_token&quot;
    accessURL <- "https://api.twitter.com/oauth/access_token&quot;
    authURL <- "https://api.twitter.com/oauth/authorize&quot;
    consumerKey <- "..scrt….IX4hvp7lm00"
    consumerSecret <- "REoChpe…scrt……..I0"
    Cred <- OAuthFactory$new(consumerKey = consumerKey,
    consumerSecret = consumerSecret,
    requestURL = requestURL,
    accessURL = accessURL,
    authURL = authURL)
    Cred$handshake()

    can you please help me.

    PS: My OS is opensue 12.3

    • Hope u dont mind if i comment.
      i ran into this same error but my advice is to follow the same step thats in this blog not this one you are using. You might want to try it on the Rgui first not rstudio.
      if it works on the Gui refresh rstudio n try it the authentication through there.

      if you still want to use this then try checkin you token n keys they might have changed.
      but if you get this error when you to register the oauth then i think registeroauth is no longer a function.

      hop this helps

  47. Hi when i try to download the twitteR package from your github account i keep getting
    “Warning message:
    Username parameter is deprecated. Please use geoffjentry/twitteR”

  48. Thank you, Julian. I find your blog is useful.
    I followed tutorial from you to get twitter authentication a couple days ago, and it worked. But now, after updated R and twitteR package to the latest version, it return error message when execute setup_twitter_oauth() function. “Error: could not find function “setup_twitter_oauth”. twitteR package and dependencies have been loaded properly. Would appreciate any suggestion and advice.

  49. Hi, I’m trying to use tha package twitteR, following what is written above.
    I installed the package as you said, and then:

    library(twitteR)

    api_key <-"…"

    api_secret <- "…"

    access_token <- "…"

    access_token_secret <- "…"

    setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)

    But this error occurs:

    [1] "Using direct authentication"
    Errore in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()'

    I don't know what is it!! can you help me?

    thank you !
    Mat

      • Hi! Two days ago I re-install R and twitteR package and now it is working!
        But one more question: I see that I can download tweets of the past, but only for the 7 previous days! I need to use older tweets? Do you have any suggestions (I’m a student, I can’t pay too much for having them).
        Thank you,
        Mattia

        • Hey
          this is because of restrictions of the Twitter API. You can just get recent tweets.
          Twitter does not talk about this limits in detail and they can vary.
          So there is no way to get old tweets. Your only way in the moment is saving the results every day and get all new tweets.

          I hope that Twitter will open their archive they created recently where they allow you to search all tweets ever written.
          Maybe they will make it accessible through their API. I will update the post if I hear something new.

          Regards

    • HI AGAIN ..
      I SOLVE the problem ..i install twitteR from github its better ..

      NOW THE thing i want most .. what is the script so can i get some user attribute ? like the time he tweet , his location if he put
      if he put a background pic >> etc
      i have a research about how to find out if this account is fake or real !!

  50. Ahoy there,

    THANK YOU for this excellent resource :) Last week I was able to use the code you have provided above to authenticate with twitter in Rstudio (windows), but it stopped working a few days ago. I’m getting this error:

    Error in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

    I’m using the latest packages (I think):
    other attached packages:
    [1] twitteR_1.1.8

    loaded via a namespace (and not attached):
    [1] bit_1.1-12 bit64_0.9-4 bitops_1.0-6 DBI_0.3.1 digest_0.6.7
    [6] httr_0.6.0 R6_2.0.1 RCurl_1.95-4.5 rjson_0.2.15 stringr_0.6.2
    [11] tools_3.1.1

    I do have Rtools installed (if that matters).

    I attempted to run your script in Rstudio (ubuntu) and found some success with it last night — but I had to clear the Rhistory and gitignore files for it to work again after restarting Rstudio…

    I’m a COMPLETE novice at all of this — feels like I’m grabbing at straws to make it work! Any insights would be greatly appreciated!

    Thank you!
    -Nickolas

  51. HI, interesting post, this is my second try to get the Twitter api and R working and I like your “variable approach”. However, the function setup_twitter_oauth does not exist in my package twitteR… (Error: could not find function “setup_twitter_oauth”) am I missing something? Thank you in advance, all the best.

    • HI, there, I have solved, the issue, it looks I have not started to read the post from the top :) sorry, anyway, I have been missing all the needed packages from the top. So far it works, thanks again for a nice and simple solution! Lovrenc

  52. Hi,
    I can use the function searchTwitter(“iphone”), however, when I try to use the dmSend(‘Testing out twitteR!’, ‘xxx’) … xxx = the reg. user of the twitter app. … anyway, the function does not work, I get the

    Error in twInterfaceObj$doAPICall(“direct_messages/new”, params = params, :
    OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

    I hope I have a typo, anyway, do you know how to make this function work?

    Thank you in advance.

      • Hi Julian, I got this error (authentication error) too since a couple days ago.
        Do you know how to solve this issue?

        Here are some infos about R session :

        R version 3.1.2 (2014-10-31)
        Platform: x86_64-w64-mingw32/x64 (64-bit)

        other attached packages:
        [1] twitteR_1.1.8

        loaded via a namespace (and not attached):
        [1] bit_1.1-12 bit64_0.9-4 DBI_0.3.1 httr_0.6.1 rjson_0.2.15
        [6] stringr_0.6.2 tools_3.1.2

        • Update.
          I tried in Linux. The problem also exist.


          > sessionInfo()
          R version 3.1.2 (2014-10-31)
          Platform: x86_64-redhat-linux-gnu (64-bit)

          locale:
          [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
          [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
          [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
          [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
          [9] LC_ADDRESS=C LC_TELEPHONE=C
          [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

          attached base packages:
          [1] stats graphics grDevices utils datasets methods base

          other attached packages:
          [1] twitteR_1.1.8 devtools_1.6.1

          loaded via a namespace (and not attached):
          [1] bit_1.1-12 bit64_0.9-4 bitops_1.0-6 DBI_0.3.1 digest_0.6.8
          [6] httr_0.6.1 R6_2.0.1 RCurl_1.95-4.5 rjson_0.2.15 stringr_0.6.2
          [11] tcltk_3.1.2 tools_3.1.2

  53. Hey, I just tried running twitteR to get authentication and search tweets. It works now. I didn’t do any update. I don’t know why I got the error a couple days ago.

    R version 3.1.2 (2014-10-31)
    Platform: x86_64-w64-mingw32/x64 (64-bit)

    locale:
    [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
    [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
    [5] LC_TIME=English_United States.1252

    attached base packages:
    [1] stats graphics grDevices utils datasets methods base

    other attached packages:
    [1] twitteR_1.1.8

    loaded via a namespace (and not attached):
    [1] bit_1.1-12 bit64_0.9-4 bitops_1.0-6 DBI_0.3.1 digest_0.6.4
    [6] httr_0.6.1 R6_2.0.1 RCurl_1.95-4.5 rjson_0.2.15 stringr_0.6.2
    [11] tools_3.1.2

  54. Hey, I am trying to use the since and until functionality:
    searchTwitter(“iPhone”, since = ‘2015-01-01′, until = ‘2015-01-31′)

    but i only get the following error:

    Warning message:
    In doRppAPICall(“search/tweets”, n, params = params, retryOnRateLimit = retryOnRateLimit, :
    25 tweets were requested but the API can only return 0

    I can use all other twitter functionality except for this, is there something wrong with my code? Or is it no longer supported? I am using R 3.1.2

    Please could you advise,

    • Hey
      your code seems to be fine. But the problem will be the Twitter API. They have very complicated restrictions especially when it comes to searching tweets on a certain date. So the API just does not give any tweets back. There is no workaround for this. You just have to try different dates and keywords and hope that the API gives you some tweets.

      Regards

  55. Hi!

    I am new to R, I am trying to extract Tweets for my thesis. When I follow all your steps, I get an error:

    > setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
    [1] “Using direct authentication”
    Use a local file to cache OAuth access credentials between R sessions?
    1: Yes
    2: No

    Selection: 1
    Adding .httr-oauth to .gitignore
    Error in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

    Earlier I also got this message
    In addition: Warning message:
    Username parameter is deprecated. Please use geoffjentry/twitteR
    –> Should I be using my own Twitterusername here?

    What am I doing wrong? I am sorry if its the basic stuff I am doing wrong, anyone helping me so much thanks in advance :)

      • Thanks so much for replying so fast, it means a lot to me (thesis time pressure and all!)

        I tried again, and I seem to be getting less errors. However, the problem is not fixed yet. My code:

        > install.packages(c(“devtools”, “rjson”, “bit64″, “httr”))
        Installing packages into ‘C:/Users/Eigenaar/Documents/R/win-library/3.1’
        (as ‘lib’ is unspecified)
        — Please select a CRAN mirror for use in this session —
        trying URL ‘http://cran.xl-mirror.nl/bin/windows/contrib/3.1/devtools_1.7.0.zip’
        Content type ‘application/zip’ length 310465 bytes (303 KB)
        opened URL
        downloaded 303 KB

        trying URL ‘http://cran.xl-mirror.nl/bin/windows/contrib/3.1/rjson_0.2.15.zip’
        Content type ‘application/zip’ length 493521 bytes (481 KB)
        opened URL
        downloaded 481 KB

        trying URL ‘http://cran.xl-mirror.nl/bin/windows/contrib/3.1/bit64_0.9-4.zip’
        Content type ‘application/zip’ length 455839 bytes (445 KB)
        opened URL
        downloaded 445 KB

        trying URL ‘http://cran.xl-mirror.nl/bin/windows/contrib/3.1/httr_0.6.1.zip’
        Content type ‘application/zip’ length 387761 bytes (378 KB)
        opened URL
        downloaded 378 KB

        package ‘devtools’ successfully unpacked and MD5 sums checked
        package ‘rjson’ successfully unpacked and MD5 sums checked
        package ‘bit64’ successfully unpacked and MD5 sums checked
        package ‘httr’ successfully unpacked and MD5 sums checked

        The downloaded binary packages are in
        C:\Users\Eigenaar\AppData\Local\Temp\Rtmp6dyFFD\downloaded_packages
        >
        # restart (no save or smth)

        > library(devtools)
        WARNING: Rtools is required to build R packages, but is not currently installed.

        Please download and install Rtools 3.1 from http://cran.r-project.org/bin/windows/Rtools/ and then run find_rtools().
        > install_github(“geoffjentry/twitteR”)
        Downloading github repo geoffjentry/twitteR@master
        Installing twitteR
        “C:/PROGRA~1/R/R-31~1.3/bin/i386/R” –vanilla CMD INSTALL “C:/Users/Eigenaar/AppData/Local/Temp/RtmpacS0VO/devtoolsb7c13d41429/geoffjentry-twitteR-563a23c” \
        –library=”C:/Users/Eigenaar/Documents/R/win-library/3.1″ –install-tests

        * installing *source* package ‘twitteR’ …
        ** R
        ** inst
        ** preparing package for lazy loading
        Creating a generic function for ‘as.data.frame’ from package ‘base’ in package ‘twitteR’
        ** help
        *** installing help indices
        ** building package indices
        ** testing if installed package can be loaded
        *** arch – i386
        *** arch – x64
        * DONE (twitteR)
        > library(twitteR)
        > setup_twitter_oauth(“XXXXXXXXXXXX”, ” xxxxxxxxxxxx”)
        [1] “Using browser based authentication”
        Use a local file to cache OAuth access credentials between R sessions?
        1: Yes
        2: No

        Selection: 1
        Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission) :
        client error: (401) Unauthorized

  56. Hi!
    I follow the instruction on github and installed the most recent version of twitteR, but when I run the code below using all 4 parameters, error still shows up

    >setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)

    [1] “Using direct authentication”
    Error in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

    What can be the cause the error?
    Can anyone help me out?

    TIA

  57. Hi,

    I am using R Studio on Windows and I have my project presentation soon so this is kind of an urgency. I have pasted my R history here. I am gettign the check_twitter_oauth() error even though I have downloaded the new version of twitteR. Please help.

    install_github(“twitteR”,”geoffjentry”)
    Downloading github repo geoffjentry/twitteR@master
    Installing twitteR
    “C:/PROGRA~1/R/R-32~1.0/bin/x64/R” –vanilla CMD INSTALL \
    “C:/Users/ChaarviGupta/AppData/Local/Temp/RtmpGWPrH3/devtoolsa0c7269407a/geoffjentry-twitteR-07d262f” \
    –library=”C:/Users/ChaarviGupta/Documents/R/win-library/3.2″ –install-tests

    * installing *source* package ‘twitteR’ …
    ** R
    ** inst
    ** preparing package for lazy loading
    Creating a generic function for ‘as.data.frame’ from package ‘base’ in package ‘twitteR’
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (twitteR)
    Reloading installed twitteR
    Warning message:
    Username parameter is deprecated. Please use geoffjentry/twitteR
    > library(twitteR)
    > api_key
    > api_secret access_token access_token_secret setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
    [1] “Using direct authentication”
    Error in check_twitter_oauth() : OAuth authentication error:
    This most likely means that you have incorrectly called setup_twitter_oauth()’

LEAVE A REPLY