3

I'm revising my original query to ask specifically if anyone can see a reason that the R-code I give below would, in of itself, lead to an invalid request token. If not, I'll know my issue lies elsewhere.

I’m trying to use the twitteR package as I’ve gotten to the Twitter chapter in Jeffrey Stanton’s free e-book on Data science which is helping me learn R. I get so far and then Twitter gives me this message:

Whoa there! The request token for this page is invalid. It may have already been used, or expired because it is too old. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

I’ve got the bitops, RCurl, RJSONIO, twitter and ROAuth packages installed. I then run this code(NB I can't post links because my reputation is too low):

reqURL <- "//api.twitter.com/oauth/request_token"
   accessURL <- "//api.twitter.com/oauth/access_token"
   authURL <- "//api.twitter.com/oauth/authorize"
   consumerKey <- "abc"
   consumerSecret <- "xyz"
   twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                                consumerSecret=consumerSecret,
                                requestURL=reqURL,
                                accessURL=accessURL,
                                authURL=authURL)

Followed by this:

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

I then get this prompt:

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

At this point I can’t seem to copy the twitter link, so I hand type it(!) into my browser and I get the message from Twitter I started my question with. I’ve tried a number of times with the same outcome. The OAuth bit in the TwitteR vignette on r-project doesn’t have anything on this (it assumes I’d have done it right I suppose!) and the example on page nine of the TwitteR package description doesn’t help me either.

Thanks.

Phil A
  • 51
  • 2
  • 6
  • Yes the inability to copy-paste that URL is a real nuisance, I know what you mean... are your 100% sure that you're not making a typo? – Ben Apr 12 '13 at 00:52
  • I did try four times to copy out URLs, but there's a chance I made a mistake each time I suppose. I guess the first question I should ask is whether anything looks weird in my code? If not, maybe I've made an error on the twitter end or something? – Phil A Apr 12 '13 at 02:04
  • are you using the pasted consumer key and secret? Or a real one? – ndoogan Apr 12 '13 at 02:11
  • Good call, but I'm using the real ones I got from twitter. – Phil A Apr 12 '13 at 02:21
  • By the way, I discovered (was tipped off) that the inability to copy-paste the URL is limited to R-Studio. Doing the handshake in the console allows you to copy-paste the URL you're prompted to follow. This is less annoying and more accurate! – Phil A Apr 26 '13 at 15:14

2 Answers2

0

I’ve kind of answered my original query myself. I quit the R-studio project I was working in, recreated my access token and access token secret from within the twitter developer site, and then applied this code in a new R-studio project:

requestURL <-  "https://api.twitter.com/oauth/request_token"
accessURL =    "https://api.twitter.com/oauth/access_token"
authURL =      "https://api.twitter.com/oauth/authorize"
consumerKey =   "------------"
consumerSecret = "-----------"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                         consumerSecret=consumerSecret,
                         requestURL=requestURL,
                         accessURL=accessURL,
                         authURL=authURL)
download.file(url="http://curl.haxx.se/ca/cacert.pem",
          destfile="cacert.pem")
twitCred$handshake(cainfo="cacert.pem")

I got that from here: TwitteR, ROAuth and Windows: register OK, but certificate verify failed

This combination of things stopped me getting the message from twitter that the request token was invalid. So I then get the link to twitter which now works: To enable the connection, please direct your web browser to: https://api.twitter.com/oauth/authorize?oauth_token=xxxx

However I didn’t get much further, so I’ve written a new question here: Where does twitteR PIN code appear during R oauth authentication?

Community
  • 1
  • 1
Phil A
  • 51
  • 2
  • 6
0

I faced the same issue . I managed in two ways: (1) Use R console instead of R studio OR (2) You take snapshot of the link and convert into text using OCR software(this)

Thanks and regards!!!

notnotundefined
  • 3,493
  • 3
  • 30
  • 39