skip to Main Content

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

2

Answers


  1. 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).

    Login or Signup to reply.
  2. My twitter bot also stopped working around June 13th. It relied on this code:

    bot <- rtweet_bot(
       api_key = Sys.getenv("api_key"),
       api_secret = Sys.getenv("api_secret_key"),
       access_token = Sys.getenv("access_token"),
       access_secret = Sys.getenv("access_token_secret")
     )
    auth_as(auth = bot)
    post_tweet(status =  "my_tweet")
    

    I also 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)
    

    I have read the question and the comments, but I still don’t understand the fix. My current understanding is that "post_tweet" no longer works and that I shold use "tweet_post". I also understand that rtweet_bot() doesnt work with tweet_post(), so I tried authenticating with rtweet_oauth2() then posting with tweet_post(). This works. However, this requires starting a browser and clicking a button to allow the app to authenticate.

    Can I still use rtweet to post automatically every day without having to monitor it?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search