1

Folks,

I'm attempting to set up automated posts to Twitter with R and rtweet. I'm following the steps outlined at https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html, and I'm hitting a roadblock.

Backdrop: I used to have an automated Twitter feed build around rtweet (a package I love), but I must have violated one of the new "usage" limits and Twitter gave me one of their unhelpful error messages. I therefore decided to start the process again. I have a free developer account with 1 project in it. For what follows I've deleted everything in that folder (i.e. the previous app), so I can set it up new.

My understanding of how to set up rtweet in the brave new Twitter world is as follows:

  1. I go into my project folder on developer.twitter.com and set up a new app. This gives me a new API Key, API key Secret and Bearer token, all of which I dutifully saved.

  2. I go into app "Keys and Tokens". Here I generate the Access Token and Access Token Secret. This should be all that's needed to pull down data from rtweet.

No sign of any errors whatsoever. Since I'm looking for bot based authentication, in R I run:

library(rtweet)
auth = rtweet_bot()
df <- search_tweets("#rstats", token = auth)

The second line sets up authentication as bot. That's where I input API Key, Secrets and Tokens. Everything seems to be going well.

Running the last line, I get:

Error: Twitter API failed [403]. Check error message at     https://developer.twitter.com/en/support/twitter-api/error-troubleshooting 
 * You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product (453)  

Not a good sign.

Since I'm ultimately interested in posting to Twitter, let's go back into the App folder - Settings, and click on "User Authentication Settings". In terms of app permissions I'm interested in "Read and Write", I select "Web App, Automated App or Bot" and as callback URL I enter "http://127.0.0.1:1410". Lastly, in the "Website URL" box I enter the link to my Twitter profile and hit save. This gives me the client ID and client secret (which rtweet never asks for).

I run the same code as above, and get the same error.

Going back into the developer portal, I see:

Twitter Screenshot

Lastly, output from sessionInfo():

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 13.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rtweet_1.2.0.9003

loaded via a namespace (and not attached):
 [1] prettyunits_1.1.1 crayon_1.5.2      withr_2.5.0       R6_2.5.1          jsonlite_1.8.4   
 [6] lifecycle_1.0.3   httr_1.4.5        rlang_1.1.0       progress_1.2.2    cli_3.6.1        
[11] curl_5.0.0        rstudioapi_0.14   vctrs_0.6.1       tools_4.1.1       hms_1.1.3        
[16] compiler_4.1.1    askpass_1.1       pkgconfig_2.0.3   openssl_2.0.6  

Any suggestions on what I'm doing wrong? I've done through the documentation multiple times by now, and as far as I can tell, I'm following every step correctly. I've gone through this now multiple times and the result is this error, so starting to be a bit confused. Help would be much appreciated!

Thanks, Philipp

PMaier
  • 592
  • 7
  • 19

1 Answers1

0

rtweet only ask for what is needed for a given authentication. The client ID and client secret are used in the OAuth2 authentication method, which is only used for the API v2 and you are using the API v1.1.

I have heard reports of new apps not being allowed to use old API endpoints not related to posting images (you cannot search with the new Free API plan). Apparently what you are doing wrong is to try to use the free plan to search tweets with the old API. What I recommend is to pay to be able to use the API v2 and be allowed to search tweets (or try to use the old app without renewing the tokens to try to avoid it and keep using the old API).

llrs
  • 3,308
  • 35
  • 68
  • Thanks for your answer - point on information asked for authentication is well taken. Regarding what is or isn't possible with the free API plan: posting to Twitter, after setting it up the same way, also isn't allowed. It results in the exact same error message. So unless I'm doing something wrong, it seems that the free plan really doesn't allow you to do anything useful via API. – PMaier Jun 19 '23 at 12:14
  • I have successfully posted via rtweet and the API v2 under the free plan, but for that you'll need the oauth2 authentication. What is "setting it up the same way", using `rtweet_bot` and `tweet_post` or using `post_tweet`? The former uses API v2 which you should be allowed, the later uses API v1 and the error message is expected. Which version of rtweet are you using? – llrs Jun 19 '23 at 13:13
  • When I say "the same way" I mean by using the steps outlined in my initial post. I just downloaded and installed the latest version from Github (1.2.0.9003), and using post_tweet I get the same error message ("Error: Twitter API failed [403]" etc.). Using tweet_post I get this: > tweet_post("Test") Error in `default_client()`: ! The default rtweet client is no longer authorized. ℹ You'll need to register as developer in order to use the Twitter API. Run `rlang::last_trace()` to see where the error occurred. That despite the fact that I just re-authenticated using rtweet_bot().... – PMaier Jun 20 '23 at 01:28
  • Using rtweet_bot authentication doesn't work with tweet_post because the API v2 requires OAuth2 authentication, check the help page of tweet_post. But it seems that rtweet tries to use the default rtweet client to authenticate and I have disable it because it no longer works (I'll try to make the error message more user friendly). – llrs Jun 20 '23 at 12:40
  • Hi, I have the same case, however, from postman if I can create a tweet with the api v2 and without OAuth2 (only with consumer key, secret and access token and token secret) as it was done in rtweet. – Jorge Pradas Jun 20 '23 at 21:25
  • 1
    Yes, the API v2, theoretically accepts the old OAuth1, but there were signs that it wouldn't last long and I didn't add support for it in rtweet. You can open a PR to add it if you wish – llrs Jun 20 '23 at 22:57