ropensci-archive/rtweet

403 error if post_follow() runs in a purrr loop but not if it runs on its own.

Closed this issue · 3 comments

The post_follow() function now mysteriously stopped working in a function, but does work one at a time.

Here is a very simple function that has worked perfectly for me before many times:

follow <- function(Yo.Account){ 
rtweet::post_follow(Yo.Account)
 Sys.sleep(round(runif(1,1,142),0)) #to prevent hitting rate limit
}

The rtweet::post_follow() function is still working.

post_follow(“example”)
Response [https://api.twitter.com/1.1/friendships/create.json?notify=FALSE&screen_name=example]
Date: 2023-03-21 02:02
Status: 200
Content-Type: application/json;charset=utf-8
Size: 2.9 kB

And my follow() function still works when done one at a time.

> follow("example") #works perfectly

Yet, it the mapped follow() function suddenly stopped working.

map(dataframe$name, follow)
Error: Twitter API failed [403]
Check error message at

The error message is not helpful. It just says forbidden.
I thought this might be the answer:

My app is already set up for auth2.0 and I regenerated all tokens again just to see if that could work. It didn’t.

The purrr library is installed. Note, this looks similar to issue #729 but my app already does have elevated status. I have run out of ideas.

I can’t figure out how this works,
dataframe$name[[1]]
[1] “example”

and this works,

follow("example")

and this sometimes works but now usually not,

follow(dataframe$name[[1]])

But this, suddenly, mysteriously, does not ever work:

map(dataframe$name, follow)

Maybe this will work with the upcoming update? Please advise. Thanks.

llrs commented

Hi @walinchus,

You mention that you regenerated all the tokens again, after doing so does rtweet still work with the examples: post_follow("_R_Foundation")?

post_follow does not use OAuth 2.0, what authentication method do you use?
Could you post the output of auth_get()?

I don't understand where does dataframe come from. Could you elaborate with what information does it have?

Without more information this seems to be a problem with the Twitter authentication method than something I can fix in rtweet. It could be that you are trying to follow some account that is protected or has been deleted since you stored it in dataframe and this results in this error. If this is the case I would need the account to verify this and to try to provide a more informative error message.

Thanks for helping out. All good questions.

The dataframe is just a tibble with a vector of screenames that I would like to follow. It works individually but not when I reiterate over it in a list.

I thought it might be an issue with protected accounts, but I tried it individually with protected accounts and that still works, it just says that it's pending. I think you are on the right track though here because I just tried this and it worked perfectly!

> test <- tibble(person = c("_R_Foundation", "example"))
> test
# A tibble: 2 × 1
  person       
  <chr>        
1 _R_Foundation
2 example      
> test$person[[1]]
[1] "_R_Foundation"
> follow(test$person[[1]])
> purrr::map(test$person, follow)
[[1]]
NULL

[[2]]
NULL

Which makes me think there's some sort of issue with the vector of names. Maybe map(dataframe$name, follow) doesn't start with follow(dataframe$name[[1]]). I will rewrite the function to keep going if it gets an error. Thanks so much for your help.

llrs commented

I'm glad you solved your question and that you found rtweet useful!