Error Code 401 - Failed Authentication - R / OAuth / HTTR



Hi all,

I used to have a bunch of scripts that would pull tweets for me, but now they aren’t working.

I’ve created a new app, with new keys, to try and start from scratch. I am absolutely baffled at why it won’t authenticate me, though.

myKey = "abc123"
mySecret = "zyx987"
myapp = oauth_app(“Twitter”, key=myKey, secret=mySecret)
token = oauth1.0_token(app = myapp, endpoint = oauth_endpoints(“twitter”))

Always returns

Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, :
Unauthorized (HTTP 401).

I am 100% certain myKey and mySecret are correct. I’ve copy and pasted them, regenerating them, like 30 times.

On my app management page, I have a name, description, website, and callback url all set.

Any ideas what I can possibly be doing wrong? I’m at a loss.


That sounds pretty odd. OAuth is time sensitive - are you sure that your machine’s time/date are synchronized?

I’m not super familiar with R, is there any way to run the code with a higher level of debug / verbosity to trace out the error message that comes back from the API? 401 has a couple of possible meanings, if you’re seeing Twitter API error code 135 for instance it would definitely be a timestamp issue.