rtweet rweet_app() fail

Hello,
I am having an issue with using rtweet_app(). If I simply run:

library(rtweet)
tweet <- get_timeline(user = "JoeBiden", n = 1)

everything works fine. When I try to authenticate as an app in the following way:

auth_as(rtweet_app())
tweet <- get_timeline(user = "JoeBiden", n = 1)

I get the following error:

Error: Twitter API failed [403]
Check error message at https://developer.twitter.com/en/support/twitter-api/error-troubleshooting

If I use rtweet_user() or simply auth_as() instead, it works fine. I tried regenerating tokens and keys but that didn’t solve the issue. I am using rtweet version 1.0.2 and R 4.2.1. Any help will be much appreciated!

Did you provide your api keys and secrets to rtweet_app? What is the output of auth_get()?
Could you run auth_sitrep() and post here the output?

I didn’t provide keys or secrets to rtweet_app, I simply called it as above, was prompted to enter the bearer token (which I entered). This is the output of the functions you mentioned:

> auth_as(rtweet_app())
> tweet <- get_timeline(user = "JoeBiden", n = 1)
Error: Twitter API failed [403]
Check error message at https://developer.twitter.com/en/support/twitter-api/error-troubleshooting
> auth_sitrep()
Tokens found on C:/Users/jakub/AppData/Roaming/R/config/R/rtweet:
           app            user_id key
default rtweet 818180936177172480   A
> auth_get()
<Twitter bearer token>
> 

Ok, sorry I was confused with what information rtweet_app required.

Thanks for providing the output, it cleared some doubts I had.
Can you successfully make any other request: use post_tweet, get_friends, get_followers…?
If you cannot do anything with the current bearer token then your bearer token is not up to date and you’ll need to refresh it and get a new one.

Just to clarify:

> auth_as()
> auth_get()
<Token>
<oauth_endpoint>
 request:   https://api.twitter.com/oauth/request_token
 authorize: https://api.twitter.com/oauth/authenticate
 access:    https://api.twitter.com/oauth/access_token
<oauth_app> rtweet
  key:    KEY_HERE
  secret: <hidden>
<credentials> oauth_token, oauth_token_secret, user_id, screen_name
---

weirdly, KEY_HERE does not correspond to the most recent API key I generated.

I think this is the default authentication provided with rtweet, so it is expected to not match what you generated. If you want to use your own user and app that you’d need to use rtweet_user

The functions you mentioned do not work either. I revoked the bearer token in the developer portal, copied it and ran the script again with the new token but that didn’t work.

I’m not sure what else suggest you. I might be misunderstanding something, as this has worked for all the users so far. Could you explain in detail what that didn’t work means? Did you get the same error from the API, a different one, an error from R, no error but nothing happened…?

Same error as above:

Error: Twitter API failed [403]
Check error message at https://developer.twitter.com/en/support/twitter-api/error-troubleshooting

Maybe there is an issue with the connection between my twitter app and R?

I don’t think so, it might be that you need to requests elevated access. Let me know if you find a solution. Good luck!

Thank you very much for your kind help, I hope you have a great day!

1 Like

Hello, I am coming with an update. I was granted elevated access and all works fine now. Again, many thanks for your help!

Great to see it was a problem with elevated access and nothing to do with rtweet. Thanks for letting me know.

:thinking: Perhaps I need to think how to detect it earlier as asking if it worked for several endpoints didn’t work.