-
Notifications
You must be signed in to change notification settings - Fork 198
get_friends() should return a 0 x 2 tibble on failure #339
Comments
I'm having this same issue, but I have to add that this is not only a problem for any code that asumes that you are recieving a two column data.frame, but is a problem for the function itself. If I run this code where the first user is a protected account I dont follow, the process stops and does not give me back anything:
|
Below is another example with a user that no longer exists. If any
|
I think this was requested in another issue, but as I don't find it now I'll leave it open hoping to be able to fix it. |
In the dev version, this now throws an error. I think this is the best that rtweet can do — I don't think it makes sense to silently drop errors because there are many potential errors that you do want to know about (e.g. your auth is bad, or your internet connection is done), and presumably even if the error is a non-existent user, you'd still want to know exactly which users didn't exist. Instead, I think you'd be better off using some standard technique for dealing with failure, e.g.: library(purrr)
users <- c("796572560821485568", "BarackObama")
results <- map(users, safely(rtweet::get_friends))
#> Reading token from ~/Library/Caches/rtweet/auth.rds
results <- transpose(results)
results$error
#> [[1]]
#> <simpleError: Twitter API failed [404]
#> * Sorry, that page does not exist. (34)>
#>
#> [[2]]
#> NULL
dplyr::bind_rows(results$result)
#> # A tibble: 5,000 x 2
#> user ids
#> <chr> <chr>
#> 1 BarackObama 1330457336
#> 2 BarackObama 30354991
#> 3 BarackObama 3157910605
#> 4 BarackObama 739119366
#> 5 BarackObama 1111940934
#> 6 BarackObama 61636488
#> 7 BarackObama 22255654
#> 8 BarackObama 22712235
#> 9 BarackObama 346197350
#> 10 BarackObama 18509818
#> # … with 4,990 more rows Created on 2021-03-05 by the reprex package (v1.0.0) |
How does this interact with However, the Maybe the fact that |
I meant that something like
It is not spelt out in |
@AltfunsMA that's not how |
Closing since now mostly fixed in dev, and the remaining bits are tracked in #510. |
Problem
When
get_friends()
fails, for example when requesting the friend list of an account that you do not have access to, it returns a0 x 0
tibble. This breaks any code that assumes you will receive a two-column tibble.Created on 2019-06-24 by the reprex package (v0.2.1)
Proposed new behavior
The text was updated successfully, but these errors were encountered: