get_friends: Get user IDs of accounts followed by target user(s).

View source: R/friends.R

get_friendsR Documentation

Get user IDs of accounts followed by target user(s).

Description

Returns a list of user IDs for the accounts following BY one or more specified users.

Usage

get_friends(
  users,
  n = 5000,
  retryonratelimit = NULL,
  cursor = "-1",
  parse = TRUE,
  verbose = TRUE,
  token = NULL,
  page = lifecycle::deprecated()
)

Arguments

users

Screen name or user ID of target user from which the user IDs of friends (accounts followed BY target user) will be retrieved.

n

Desired number of results to return. Results are downloaded in pages when n is large; the default value will download a single page. Set n = Inf to download as many results as possible.

The Twitter API rate limits the number of requests you can perform in each 15 minute period. The easiest way to download more than that is to use retryonratelimit = TRUE.

You are not guaranteed to get exactly n results back. You will get fewer results when tweets have been deleted or if you hit a rate limit. You will get more results if you ask for a number of tweets that's not a multiple of page size, e.g. if you request n = 150 and the page size is 200, you'll get 200 results back.

retryonratelimit

If TRUE, and a rate limit is exhausted, will wait until it refreshes. Most Twitter rate limits refresh every 15 minutes. If FALSE, and the rate limit is exceeded, the function will terminate early with a warning; you'll still get back all results received up to that point. The default value, NULL, consults the option rtweet.retryonratelimit so that you can globally set it to TRUE, if desired.

If you expect a query to take hours or days to perform, you should not rely solely on retryonratelimit because it does not handle other common failure modes like temporarily losing your internet connection.

cursor

Which page of results to return. The default will return the first page; you can supply the result from a previous call to continue pagination from where it left off.

parse

If TRUE, the default, returns a tidy data frame. Use FALSE to return the "raw" list corresponding to the JSON returned from the Twitter API.

verbose

Show progress bars and other messages indicating current progress?

token

Use this to override authentication for a single API call. In many cases you are better off changing the default for all calls. See auth_as() for details.

page

[Deprecated] Please use cursor instead.

Details

Generally, you should not need to set n to more than 5,000 since Twitter limits the number of people that you can follow (i.e. to follow more than 5,000 people at least 5,000 people need to follow you).

Value

A tibble data frame with two columns, "from_id" for name or ID of target user and "to_id" for accounts ID they follow.

Note

If a user is protected the API will omit all requests so you'll need to find which user is protected. rtweet will warn you and the output will be NA.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids

Examples

if (auth_has_default()) {
users <- get_friends("ropensci")
users
}

rtweet documentation built on Oct. 17, 2023, 1:11 a.m.