safe_get_friends: Safely get friend list of Twitter users

Description Usage Arguments Details Value

View source: R/api-calls.R

Description

safe_get_friends() is a drop-in replacement for rtweet::get_friends() that automatically respects Twitter API rate limits and coordinates use of multiple Twitter access tokens that have been registered with register_token(). At the moment you can only request the friends list of 15 or fewer users in a single call.

Usage

1
safe_get_friends(users, n = 5000, page = -1, verbose = FALSE, attempts = 5)

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

Number of friends (user IDs) to return. Defaults to 5,000, which is the maximum returned by a single API call. Users are limited to 15 of these requests per 15 minutes. Twitter limits the number of friends a user can have to 5,000. To follow more than 5,000 accounts (to have more than 5 thousand "friends") accounts must meet certain requirements (e.g., a certain ratio of followers to friends). Consequently, the vast majority of users follow fewer than five thousand accounts. This function has been oriented accordingly (i.e., it assumes the maximum value of n is 5000). To return more than 5,000 friends for a single user, call this function multiple times with requests after the first using the page parameter.

page

Default page = -1 specifies first page of JSON results. Other pages specified via cursor values supplied by Twitter API response object. This is only relevant if a user has over 5000 friends (follows more than 5000 accounts).

verbose

Logical indicating whether or not to include output messages. Defaults to TRUE, which includes printing a success message for each inputted user.

attempts

How many times should we attempt to access the Twitter API before giving up? Defaults to 5.

Details

If no tokens have been registered with socialsampler, safe_get_friends() will look for a token registered with rtweet and use that token instead, again automatically respecting rate limits. If no tokens have been registered with either socialsampler or rtweet, you'll get an error.

Value

An edgelist with columns:


alexpghayes/socialsampler documentation built on Jan. 3, 2022, 6:54 p.m.