Package 'rtweet'

Title: Collecting Twitter Data
Description: An implementation of calls designed to collect and organize Twitter data via Twitter's REST and stream Application Program Interfaces (API), which can be found at the following URL: <https://developer.twitter.com/en/docs>.
Authors: Michael W. Kearney [aut] , Lluís Revilla Sancho [aut, cre] , Hadley Wickham [aut] , Andrew Heiss [rev] , Francois Briatte [rev], Jonathan Sidi [ctb]
Maintainer: Lluís Revilla Sancho <[email protected]>
License: MIT + file LICENSE
Version: 2.0.0.9000
Built: 2024-10-01 06:24:06 UTC
Source: https://github.com/ropensci/rtweet

Help Index


Mark a user id as a screen name

Description

There are two ways to identify a Twitter user: a screen name (e.g. "justinbieber") or a user identifier (e.g. "27260086"). User identifiers look like regular numbers, but are actually 64-bit integers which can't be stored in R's numeric vectors. For this reason, rtweet always returns ids as strings.

Unfortunately this introduces an ambiguity, because user names can also consist solely of numbers (e.g. "123456") so it's not obvious whether a string consisting only of numbers is a screen name or a user id. By default, rtweet will assume its a user id, so if you have a screen name that consists only of numbers, you'll need to use as_screenname() to tell rtweet that it's actually a screen name.

Note that in general, you are best off using user ids; screen names are not static and may change over longer periods of time.

Usage

as_screenname(x)

Arguments

x

A character vector of Twitter screen names.

See Also

Other users: lists_subscribers(), lookup_users(), search_users()


Set default authentication for the current session

Description

auth_as() sets up the default authentication mechanism used by all rtweet API calls. See rtweet_user() to learn more about the three available authentication options.

Usage

auth_as(auth = NULL)

Arguments

auth

One of the following options:

Value

Invisibly returns the previous authentication mechanism.

See Also

auth_sitrep() to help finding and managing authentications.

Other authentication: auth_get(), auth_save(), auth_setup_default(), rtweet_user()

Examples

## Not run: 
# Use app auth for the remainder of this session:
my_app <- rtweet_app()
auth_as(my_app)

# Switch back to the default user based auth
auth_as()

# Load auth saved by auth_save()
auth_as("my-saved-app")

## End(Not run)

Remove tokens

Description

If there is a file with saved tokens it will delete it.

Usage

auth_clean(old = TRUE, new = FALSE)

Arguments

old

A logical value if you want to remove old tokens.

new

A logical value if you want to remove new tokens.

Details

This functions helps to comply with CRAN policy to remove files created by the package.

Value

An invisible logical value showing the success of the operation. If no tokens need to be deleted it will return FALSE too. NULL if there is nothing to do.

Examples

auth_clean(TRUE, TRUE)

Get the current authentication mechanism

Description

If no authentication has been set up for this session, auth_get() will call auth_as() to set it up.

Usage

auth_get()

Value

The current token used.

See Also

Other authentication: auth_as(), auth_save(), auth_setup_default(), rtweet_user()

Examples

## Not run: 
auth_get()

## End(Not run)

Save an authentication mechanism for use in a future session

Description

Use auth_save() with auth_as() to avoid repeatedly entering app credentials, making it easier to share auth between projects. Use auth_list() to list all saved credentials.

Usage

auth_save(auth, name)

auth_list()

Arguments

auth

One of rtweet_app(), rtweet_bot(), or rtweet_user().

name

Name of the file to use.

Details

The tokens are saved on tools::R_user_dir("rtweet", "config").

Value

Invisible the path where the authentication is saved.

See Also

auth_sitrep() to help finding and managing authentications.

Other authentication: auth_as(), auth_get(), auth_setup_default(), rtweet_user()

Examples

## Not run: 
# save app auth for use in other sessions
auth <- rtweet_app()
auth_save(auth, "my-app")

# later, in a different session...
auth_as("my-app")
# Show all authentications stored
auth_list()

## End(Not run)

Set up default authentication

Description

You'll need to run this function once per computer so that rtweet can use your personal Twitter account. See rtweet_app()/rtweet_bot and auth_save() for other authentication options.

Usage

auth_setup_default()

auth_has_default()

Details

It will use the current logged in account on the default browser to detect the credentials needed for rtweet and save them as "default". If a default is found it will use it instead.

Value

auth_setup_default(): Invisibly returns the previous authentication mechanism. auth_has_default(): A logical value TRUE if there is a default authentication.

See Also

Other authentication: auth_as(), auth_get(), auth_save(), rtweet_user()

Examples

## Not run: 
if (!auth_has_default() && interactive()) {
   auth_setup_default()
}

## End(Not run)

Twitter Tokens sitrep

Description

Get a situation report of your current tokens; useful for upgrading from rtweet 0.7.0 to 1.0.0 and diagnosing problems with tokens.

Usage

auth_sitrep()

Details

Prints rtweet tokens on the old folder (rtweet < 0.7.0) and on the new (rtweet > 1.0.0) default location. For each folder it reports apps and then users and bots authentications. For users authentications it reports the user_id, so that you can check who is that user.

Users should follow its advise, if there is no advise but there are still some problems authenticating regenerate the authentications.

Value

Invisibly, TRUE if some problems were found and FALSE otherwise

Note

It is safe to use in public, as instead of the tokens or keys it reports a letter.

See Also

auth_as()

Examples

auth_sitrep()

Clean text of tweets

Description

Removes from the text, users mentions, hashtags, urls and media. Some urls or other text might remain if it is not recognized as an entity by the API. [Deprecated]

Usage

clean_tweets(x, clean = c("users", "hashtags", "urls", "media"))

Arguments

x

Tweets

clean

Type of elements to be removed.

Value

A vector with the text without the entities selected

See Also

rtweet-deprecated


Set default client for the current session

Description

client_as() sets up the default client used by rtweet API calls with PKCE. See rtweet_user() to learn more about the three available authentication options.

Usage

client_as(client = NULL)

Arguments

client

One of the following options:

  • NULL, the default, will look for rtweet's "default" authentication which uses your personal default Twitter client. If it's not found, it will call client_setup_default() to set it up.

  • A string giving the name of a saved auth file made by client_save().

  • A client object created by rtweet_client().

Value

Invisibly returns the previous authentication mechanism.

See Also

Other client: client_get(), client_has_default(), client_save()

Examples

## Not run: 
# Use app auth for the remainder of this session:
my_app <- rtweet_app()
auth_as(my_app)

# Switch back to the default user based auth
client_as()
client_list()

## End(Not run)

Clean clients

Description

Removes the rtweet clients directory.

Usage

client_clean()

Value

Either TRUE if folder could be deleted or FALSE.

Examples

client_clean()

Get the current client

Description

If no client has been set up for this session, client_get() will call client_as() to set it up.

Usage

client_get()

Value

The current client used.

See Also

Other client: client_as(), client_has_default(), client_save()

Examples

## Not run: 
client_get()

## End(Not run)

Set up default client

Description

You'll need to run this function once per computer so that rtweet can use your client.

Usage

client_has_default()

client_setup_default()

Details

It will use the current default account for rtweet and save them as "rtweet". If a default is found it will use it instead.

Value

client_setup_default(): Invisibly returns the previous authentication mechanism. client_has_default(): A logical value TRUE if there is a default authentication.

See Also

Other client: client_as(), client_get(), client_save()

Examples

## Not run: 
if (!client_has_default()) {
   client_setup_default()
}

## End(Not run)

Save an authentication mechanism for use in a future session

Description

Use client_save() with client_as() to avoid repeatedly entering app credentials, making it easier to share auth between projects. Use client_list() to list all saved credentials.

Usage

client_save(client)

client_list()

Arguments

client

A client rtweet_client().

Details

The tokens are saved on the clients folder in tools::R_user_dir("rtweet", "config").

Value

Invisible the path where the client is saved.

See Also

auth_sitrep() to help finding and managing authentications.

Other client: client_as(), client_get(), client_has_default()

Examples

## Not run: 
# save app client for use in other sessions
client <- rtweet_client()
client_save(client)

# later, in a different session...
client_as("my-app")
# Show all authentications stored
client_list()

## End(Not run)

Get direct messages sent to and received by the authenticating user from the past 30 days

Description

Returns all Direct Message events (both sent and received) within the last 30 days. Sorted in reverse-chronological order. Includes detailed information about the sender and recipient. [Deprecated]

Usage

direct_messages(
  n = 50,
  cursor = NULL,
  next_cursor = NULL,
  parse = TRUE,
  token = NULL,
  retryonratelimit = NULL,
  verbose = TRUE
)

Arguments

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.

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.

next_cursor

[Deprecated] Use cursor instead.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

Value

A list with one element for each page of results.

References

https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events

See Also

rtweet-deprecated

Examples

## Not run: 

## get my direct messages
direct_messages()


## End(Not run)

Binds list of data frames while preserving attribute (tweets or users) data.

Description

Row bind lists of tweets/users data whilst also preserving and binding users/tweets attribute data. [Deprecated]

Usage

do_call_rbind(x)

Arguments

x

List of parsed tweets data or users data, each of which presumably contains an attribute of the other (i.e., users data contains tweets attribute; tweets data contains users attribute).

Value

A single merged (by row) data frame (tbl) of tweets or users data that also contains as an attribute a merged (by row) data frame (tbl) of its counterpart, making it accessible via the users_data() or tweets_data() extractor functions.

See Also

rtweet-deprecated


Defunct: Emojis codes and descriptions data.

Description

This data comes from "Unicode.org": https://unicode.org/emoji/charts/full-emoji-list.html. The data are codes and descriptions of Emojis.

Format

A tibble with two variables and 2,623 observations.


Extract methods

Description

Extract entities of the tweets linked to a tweet id.

Usage

entity(x, entity, ...)

Arguments

x

A tweets object of the rtweet package.

entity

A entity to extract data from.

...

Other possible arguments currently ignored.

Details

The position of where does this occur is not provided.

Value

Some information about those entities and the tweet id it comes from. for users mentions the ids of the mentioned users are "user_id", "user_id_str" (not "id_str")


Expansions

Description

Twitter parameters to add more fields on the returned values.

Usage

set_expansions(
  tweet = tweet_expansions(),
  user = user_expansions(),
  list = list_expansions()
)

tweet_expansions(attachments = TRUE, referenced_tweets = TRUE)

user_expansions()

list_expansions()

Arguments

tweet, user, list

tweet_expansions(), user_expansions() and tweet_expansions().

attachments

Add attachments values? Default yes.

referenced_tweets

Add referenced_tweets values? Default yes.

Details

The set_expansions can be used to prepare the arguments for other rtweet functions.

Value

A character with the characters of valid expansions.

References

https://developer.twitter.com/en/docs/twitter-api/expansions

See Also

Fields, set_fields()

Examples

tweet_expansions()
user_expansions()
set_expansions()

Fields

Description

Arguments of expansion that select which values are returned. Fields are possible for:

Usage

media_fields

place_fields

poll_fields

list_fields

tweet_fields

user_fields

metrics_fields

Format

An object of class character of length 13.

An object of class character of length 8.

An object of class character of length 5.

An object of class character of length 6.

An object of class character of length 18.

An object of class character of length 15.

An object of class character of length 4.

References

https://developer.twitter.com/en/docs/twitter-api/fields

See Also

Expansions, set_fields()

Examples

media_fields
place_fields
poll_fields
tweet_fields
user_fields

flatten/unflatten data frame

Description

Converts list columns that containing all atomic elements into character vectors and vice versa (for appropriate named variables according to the rtweet package)

Usage

flatten(x)

unflatten(x)

Arguments

x

Data frame with list columns or converted-to-character (flattened) columns.

Details

If recursive list columns are contained within the data frame, relevant columns will still be converted to atomic types but output will also be accompanied with a warning message.

flatten flattens list columns by pasting them into a single string for each observations. For example, a tweet that mentions four other users, for the mentions_user_id variable, it will include the four user IDs separated by a space.

'unflatten“ splits on spaces to convert into list columns any columns with the following names: hashtags, symbols, urls_url, urls_t.co, urls_expanded_url, media_url, media_t.co, media_expanded_url, media_type, ext_media_url, ext_media_t.co, ext_media_expanded_url, mentions_user_id, mentions_screen_name, geo_coords, coords_coords, bbox_coords, mentions_screen_name

Value

If flattened, then data frame where non-recursive list columns—that is, list columns that contain only atomic, or non-list, elements—have been converted to character vectors. If unflattened, this function splits on spaces columns originally returned as lists by functions in rtweet package. See details for more information.

See Also

Other datafiles: read_twitter_csv(), write_as_csv()

Other datafiles: read_twitter_csv(), write_as_csv()


Get tweets liked/favorited by one or more users

Description

Returns up to 3,000 tweets liked/favorited for each user. [Deprecated]

Usage

get_favorites(
  user,
  n = 200,
  since_id = NULL,
  max_id = NULL,
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL
)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

since_id

Supply a vector of ids or a data frame of previous results to find tweets newer than since_id.

max_id

Supply a vector of ids or a data frame of previous results to find tweets older than max_id.

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.

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.

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.

Value

A tibble with one row for each tweet.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-favorites-list

See Also

rtweet-deprecated

Other tweets: get_mentions(), get_timeline(), lists_statuses(), lookup_tweets(), search_tweets()

Examples

if (FALSE) {
  get_favorites("KFC")
}

Get user IDs for accounts following target user.

Description

Returns a list of user IDs for the accounts following specified user. [Deprecated]

Usage

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

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

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.

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.

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.

Value

A tibble data frame with one column named "from_id" with the followers and another one "to_id" with the user used as input.

References

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

See Also

rtweet-deprecated

Examples

if (FALSE) {
  users <- get_followers("_R_Foundation")
}

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. [Deprecated]

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

See Also

rtweet-deprecated

Examples

if (FALSE) {
  get_friends("ropensci")
}

Get mentions for the authenticating user.

Description

Returns data on up to 200 of the most recent mentions (Tweets containing a users' screen_name) of the authenticating user. The timeline returned is the equivalent of the one seen when you view your mentions on twitter.com. [Deprecated]

Usage

get_mentions(
  n = 200,
  since_id = NULL,
  max_id = NULL,
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL,
  ...
)

Arguments

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.

since_id

Supply a vector of ids or a data frame of previous results to find tweets newer than since_id.

max_id

Supply a vector of ids or a data frame of previous results to find tweets older than max_id.

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.

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.

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.

...

Other arguments passed as parameters in composed API query.

Value

Tibble of mentions data.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/overview

See Also

rtweet-deprecated

Other tweets: get_favorites(), get_timeline(), lists_statuses(), lookup_tweets(), search_tweets()


Get the most recent retweets/retweeters

Description

get_retweets() returns the 100 most recent retweets of a tweet; get_retweeters() returns the 100 most recent users who retweeted them.

Usage

get_retweets(status_id, n = 100, parse = TRUE, token = NULL, ...)

get_retweeters(status_id, n = 100, parse = TRUE, token = NULL)

Arguments

status_id

Tweet/status id.

n

Number of results to retrieve. Must be <= 100.

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.

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.

...

Other arguments used as parameters in the query sent to Twitter's rest API, for example, trim_user = TRUE.

Value

Tweets data of the most recent retweets/retweeters of a given status.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweets-id

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-retweeters-ids


Get one or more user timelines

Description

get_timeline() returns the timeline of any Twitter user (i.e. what they have tweeted). get_my_timeline() returns the home timeline for the authenticated user (i.e. the tweets you see when you log into Twitter). [Deprecated] At most up to 3,200 of a user's most recent Tweets can be retrieved.

Usage

get_timeline(
  user = NULL,
  n = 100,
  since_id = NULL,
  max_id = NULL,
  home = FALSE,
  parse = TRUE,
  check = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL,
  ...
)

get_my_timeline(
  n = 100,
  since_id = NULL,
  max_id = NULL,
  parse = TRUE,
  check = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL,
  ...
)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

since_id

Supply a vector of ids or a data frame of previous results to find tweets newer than since_id.

max_id

Supply a vector of ids or a data frame of previous results to find tweets older than max_id.

home

Logical, indicating whether to return a "user" timeline (the default, what a user has tweeted/retweeted) or a "home" timeline (what the user would see if they logged into twitter).

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.

check

[Deprecated]

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.

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.

...

Further arguments passed on as parameters in API query.

Value

A tbl data frame of tweets data with users data attribute.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/overview

See Also

user_timeline(), rtweet-deprecated

Other tweets: get_favorites(), get_mentions(), lists_statuses(), lookup_tweets(), search_tweets()


Fetch Twitter OAuth token

Description

[Deprecated] Please use auth_get() instead.

Usage

get_token()

get_tokens()

See Also

Other tokens: create_token(), rate_limit()


Extract the ids

Description

Extract the ids of the rtweet data if present. Depending on the object type it returns either users ids, tweet ids or rules ids.

Usage

ids(x, ...)

Arguments

x

An object of the rtweet package.

...

Other arguments currently unused.


Defunct: Language codes recognized by Twitter data.

Description

This data comes from the Library of Congress, https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt. The data are descriptions and codes associated with internationally recognized languages. Variables include translations for each language represented as bibliographic, terminological, alpha, English, and French.

Format

A tibble with five variables and 486 observations.


Adds single-point latitude and longitude variables to tweets data.

Description

Appends parsed Twitter data with latitude and longitude variables using all available geolocation information.

Usage

lat_lng(
  x,
  coords = c("coords_coords", "bbox_coords", "geo_coords"),
  prefs = "bbox_coords"
)

Arguments

x

Parsed Twitter data as returned by various rtweet functions. This should be a data frame with variables such as "bbox_coords", "coords_coords", and "geo_coords" (among other non-geolocation Twitter variables).

coords

Names of variables containing latitude and longitude coordinates. Priority is given to bounding box coordinates (each obs consists of eight entries) followed by the supplied order of variable names. Defaults to "bbox_coords", "coords_coords", and "geo_coords") (which are the default column names of data returned by most status-oriented rtweet functions).

prefs

Preference of coordinates to use as default, must be in coords.

Details

On occasion values may appear to be outliers given a previously used query filter (e.g., when searching for tweets sent from the continental US). This is typically because those tweets returned a large bounding box that overlapped with the area of interest. This function converts boxes into their geographical midpoints, which works well in the vast majority of cases, but sometimes includes an otherwise puzzling result.

Value

Returns updated data object with full information latitude and longitude vars.

See Also

Other geo: lookup_coords()


List followers of a specified list

Description

Looks up the followers of a list.

Usage

list_followers(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the user information of who is following the list: id, name, and username. Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, list = NULL).

  • Fields: set_fields(media = NULL, poll = NULL, place = NULL, list = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers

Examples

if (FALSE) {
  lf <- list_followers("1150793074420998146")
}

List information

Description

Looks up information about a list.

Usage

list_get(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the user information of who is included in the list: id, name, and username.

Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, user = NULL)

  • Fields: set_fields(place = NULL, poll = NULL, media = NULL, tweet = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id

Examples

if (FALSE) {
  lg <- list_get("1306285118877831168")
}

List of members from a specified List

Description

Looks up the users of a list.

Usage

list_members(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the user information of who is included in the list: id, name, and username.

Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, list = NULL)

  • Fields: set_fields(place = NULL, poll = NULL, media = NULL, list = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id

Examples

if (FALSE) {
  lm <- list_members("1306285118877831168")
}

Lists a specified user is a member of.

Description

Lists a specified user is a member of.

Usage

list_membership(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with information of the list: id, name.

Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, user = NULL).

  • Fields: set_fields(place = NULL, poll = NULL, media = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id

Examples

if (FALSE) {
  lm <- list_membership("20815041")
}

Lists tweets of a specified list

Description

Looks up the followers of a list.

Usage

list_tweets(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the user information of who is following the list: edit_history_tweet_ids, id and text. Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(list = NULL).

  • Fields: set_fields(list = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets

Examples

if (FALSE) {
  lt <- list_tweets("1150793074420998146")
}

Get Twitter list members (users on a given list).

Description

Get Twitter list members (users on a given list).

Usage

lists_members(
  list_id = NULL,
  slug = NULL,
  owner_user = NULL,
  n = 5000,
  cursor = "-1",
  token = NULL,
  retryonratelimit = NULL,
  verbose = TRUE,
  parse = TRUE,
  ...
)

Arguments

list_id

required The numerical id of the list.

slug

required You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_user parameters.

owner_user

optional The screen name or user ID of the user

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.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

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.

...

Other arguments used as parameters in query composition.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members

See Also

Other lists: lists_statuses(), lists_subscribers(), lists_subscriptions(), lists_users()


Get Twitter list memberships (lists containing a given user)

Description

Due to deleted or removed lists, the returned number of memberships is often less than the provided n value. This is a reflection of the API and not a unique quirk of rtweet.

Usage

lists_memberships(
  user = NULL,
  n = 200,
  cursor = "-1",
  filter_to_owned_lists = FALSE,
  token = NULL,
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  previous_cursor = NULL
)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

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.

filter_to_owned_lists

When TRUE, will return only lists that authenticating user owns.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

previous_cursor

[Deprecated] Please use cursor instead.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships

See Also

rtweet-deprecated


Get a timeline of tweets authored by members of a specified list.

Description

Get a timeline of tweets authored by members of a specified list.

Usage

lists_statuses(
  list_id = NULL,
  slug = NULL,
  owner_user = NULL,
  since_id = NULL,
  max_id = NULL,
  n = 200,
  include_rts = TRUE,
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL
)

Arguments

list_id

required The numerical id of the list.

slug

required You can identify a list by its slug instead of its numerical id. If you decide to do so, note that you'll also have to specify the list owner using the owner_id or owner_screen_name parameters.

owner_user

optional The screen name or user ID of the user who owns the list being requested by a slug.

since_id

Supply a vector of ids or a data frame of previous results to find tweets newer than since_id.

max_id

Supply a vector of ids or a data frame of previous results to find tweets older than max_id.

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.

include_rts

optional When set to either true, t or 1, the list timeline will contain native retweets (if they exist) in addition to the standard stream of tweets. The output format of retweeted tweets is identical to the representation you see in home_timeline.

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.

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.

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.

Value

data

See Also

Other lists: lists_members(), lists_subscribers(), lists_subscriptions(), lists_users()

Other tweets: get_favorites(), get_mentions(), get_timeline(), lookup_tweets(), search_tweets()


Get subscribers of a specified list.

Description

Get subscribers of a specified list.

Usage

lists_subscribers(
  list_id = NULL,
  slug = NULL,
  owner_user = NULL,
  n = 5000,
  cursor = "-1",
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL
)

Arguments

list_id

required The numerical id of the list.

slug, owner_user

The list name (slug) and owner.

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.

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.

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.

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.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers

See Also

Other lists: lists_members(), lists_statuses(), lists_subscriptions(), lists_users()

Other users: as_screenname(), lookup_users(), search_users()


Get list subscriptions of a given user but does not include the user's own lists.

Description

Get list subscriptions of a given user but does not include the user's own lists.

Usage

lists_subscriptions(
  user,
  n = 20,
  cursor = "-1",
  parse = TRUE,
  retryonratelimit = NULL,
  verbose = TRUE,
  token = NULL
)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

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.

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.

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.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions

See Also

Other lists: lists_members(), lists_statuses(), lists_subscribers(), lists_users()


Get all lists a specified user subscribes to, including their own.

Description

Get all lists a specified user subscribes to, including their own.

Usage

lists_users(user = NULL, reverse = FALSE, token = NULL, parse = TRUE)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

reverse

optional Set this to true if you would like owned lists to be returned first. See description above for information on how this parameter works.

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.

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.

Value

data

See Also

Other lists: lists_members(), lists_statuses(), lists_subscribers(), lists_subscriptions()


Get coordinates of specified location.

Description

Convenience function for looking up latitude/longitude coordinate information for a given location. Returns data as a special "coords" object, which is specifically designed to interact smoothly with other relevant package functions. NOTE: USE OF THIS FUNCTION REQUIRES A VALID GOOGLE MAPS API KEY.

Usage

lookup_coords(address, components = NULL, apikey = NULL, ...)

Arguments

address

Desired location typically in the form of place name, subregion, e.g., address = "lawrence, KS". Also accepts the name of countries, e.g., address = "usa", address = "brazil" or states, e.g., address = "missouri" or cities, e.g., address = "chicago". In most cases using only address should be sufficient.

components

Unit of analysis for address e.g., components = "country:US". Potential components include postal_code, country, administrative_area, locality, route.

apikey

A valid Google Maps API key. If NULL, lookup_coords() will look for a relevant API key stored as an environment variable (e.g., GOOGLE_MAPS_KEY).

...

Additional arguments passed as parameters in the HTTP request

Details

Since Google Maps implemented stricter API requirements, sending requests to Google's API isn't very convenient. To enable basic uses without requiring a Google Maps API key, a number of the major cities throughout the word and the following two larger locations are baked into this function: 'world' and 'usa'. If 'world' is supplied then a bounding box of maximum latitutde/longitude values, i.e., c(-180, -90, 180, 90), and a center point c(0, 0) are returned. If 'usa' is supplied then estimates of the United States' bounding box and mid-point are returned. To specify a city, provide the city name followed by a space and then the US state abbreviation or country name. To see a list of all included cities, enter rtweet:::citycoords in the R console to see coordinates data.

Value

Object of class coords.

See Also

Other geo: lat_lng()

Examples

## Not run: 

## get coordinates associated with the following addresses/components
sf <- lookup_coords("san francisco, CA", "country:US")
usa <- lookup_coords("usa")
lnd <- lookup_coords("london")
bz <- lookup_coords("brazil")


## End(Not run)

Lookup friendship information between two specified users.

Description

Gets information on friendship between two Twitter users.

Usage

lookup_friendships(source, target, parse = TRUE, token = NULL)

Arguments

source

Screen name or user id of source user.

target

Screen name or user id of target user.

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.

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.

References

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

See Also

Other friends: my_friendships()


Get tweets data for given statuses (status IDs).

Description

[Deprecated]

Usage

lookup_tweets(
  statuses,
  parse = TRUE,
  token = NULL,
  retryonratelimit = NULL,
  verbose = TRUE
)

Arguments

statuses

User id or screen name of target user.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

Value

A tibble of tweets data.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-lookup

See Also

tweet_search_recent(), rtweet-deprecated

Other tweets: get_favorites(), get_mentions(), get_timeline(), lists_statuses(), search_tweets()


Get Twitter users data for given users (user IDs or screen names).

Description

Get Twitter users data for given users (user IDs or screen names).

Usage

lookup_users(
  users,
  parse = TRUE,
  token = NULL,
  retryonratelimit = NULL,
  verbose = TRUE
)

Arguments

users

User id or screen name of target user.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

Value

A tibble of users data.

References

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

See Also

Other users: as_screenname(), lists_subscribers(), search_users()

Examples

if (FALSE) {
    users <- c("twitter", "rladiesglobal", "_R_Foundation")
    users <- lookup_users(users)
}

Lookup friendship information between users.

Description

Gets information on friendship between authenticated user and up to 100 other users.

Usage

my_friendships(user, parse = FALSE, token = NULL)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

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.

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.

References

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

See Also

Other friends: lookup_friendships()


Network data

Description

  • network_data() returns a data frame that can easily be converted to various network classes.

  • network_graph() returns a igraph object

Usage

network_data(x, e = c("mention", "retweet", "reply", "quote"))

network_graph(x, e = c("mention", "retweet", "reply", "quote"))

Arguments

x

Data frame returned by rtweet function

e

Type of edge/link–i.e., "mention", "retweet", "quote", "reply". This must be a character vector of length one or more. This value will be split on punctuation and space (so you can include multiple types in the same string separated by a comma or space). The values "all" and "semantic" are assumed to mean all edge types, which is equivalent to the default value of c("mention", "retweet", "reply", "quote")

Details

Retrieve data to know which users are connected to which users. [Deprecated]

Value

A from/to data edge data frame

An igraph object

See Also

network_graph() rtweet-deprecated


Parser of stream

Description

Converts Twitter stream data (JSON file) into parsed data frame. [Deprecated]

Usage

parse_stream(path, ...)

Arguments

path

Character, name of JSON file with data collected by stream_tweets().

...

Unused, keeping it for back compatibility.

See Also

stream_tweets(), rtweet-deprecated

Examples

## Not run: 
stream_tweets(timeout = 1, file_name = "stream.json", parse = FALSE)
parse_stream("stream.json")

## End(Not run)

Clean up character vector (tweets) to more of a plain text.

Description

Removes links, linebreaks, fancy spaces and apostrophes and convert everything to ASCII text. Deprecated to be defunct for next release as there are better text processing tools.

Usage

plain_tweets(x)

Arguments

x

The desired character vector or data frame/list with named column/element "text" to be cleaned and processed.

Value

Data reformatted with ascii encoding and normal ampersands and without URL links, line breaks, fancy spaces/tabs, fancy apostrophes,


Delete status of user's Twitter account [Deprecated]

Description

Deletes a status of user's profile.

Usage

post_destroy(destroy_id, token = NULL)

Arguments

destroy_id

To delete a status, supply the single status ID here. If a character string is supplied, overriding the default (NULL), then a destroy request is made (and the status text and media attachments) are irrelevant.

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.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-destroy-id

See Also

tweet_delete() rtweet-deprecated


Favorites target status id.

Description

[Deprecated]

Usage

post_favorite(
  status_id,
  destroy = FALSE,
  include_entities = FALSE,
  token = NULL
)

Arguments

status_id

Status id of target tweet.

destroy

Logical indicating whether to post (add) or remove (delete) target tweet as favorite.

include_entities

Logical indicating whether to include entities object in return.

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.

References

Create: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-create Destroy: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-favorites-destroy

See Also

rtweet-deprecated

Other post: post_follow(), post_friendship(), post_tweet()


Follows target Twitter user.

Description

[Deprecated]

Usage

post_follow(
  user,
  destroy = FALSE,
  mute = FALSE,
  notify = FALSE,
  retweets = TRUE,
  token = NULL
)

post_unfollow_user(user, token = NULL)

post_mute(user, token = NULL)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

destroy

Logical indicating whether to post (add) or remove (delete) target tweet as favorite.

mute

Logical indicating whether to mute the intended friend (you must already be following this account prior to muting them)

notify

Logical indicating whether to enable notifications for target user. Defaults to false.

retweets

Logical indicating whether to enable retweets for target user. Defaults to true.

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.

References

Update: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-update Create: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create Destroy: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy Mute: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create

See Also

rtweet-deprecated

Other post: post_favorite(), post_friendship(), post_tweet()


Updates friendship notifications and retweet abilities.

Description

Updates friendship notifications and retweet abilities.

Usage

post_friendship(user, device = FALSE, retweets = FALSE, token = NULL)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

device

Logical indicating whether to enable or disable device notifications from target user behaviors. Defaults to false.

retweets

Logical indicating whether to enable or disable retweets from target user behaviors. Defaults to false.

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.

References

https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/post-friendships-update

See Also

Other post: post_favorite(), post_follow(), post_tweet()


Manage Twitter lists

Description

Create, add users, and destroy Twitter lists. [Deprecated]

Usage

post_list(
  users = NULL,
  name = NULL,
  description = NULL,
  private = FALSE,
  destroy = FALSE,
  list_id = NULL,
  slug = NULL,
  token = NULL
)

Arguments

users

Character vectors of users to be added to list.

name

Name of new list to create.

description

Optional, description of list (single character string).

private

Logical indicating whether created list should be private. Defaults to false, meaning the list would be public. Not applicable if list already exists.

destroy

Logical indicating whether to delete a list. Either list_id or slug must be provided if destroy = TRUE.

list_id

Optional, numeric ID of list.

slug

Optional, list slug.

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.

Value

Response object from HTTP request.

References

Create: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-create Destroy: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy Add users: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create, https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all Remove users: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy, https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all

See Also

rtweet-deprecated


Posts direct message from user's Twitter account

Description

Posts direct message from user's Twitter account

Usage

post_message(text, user, media = NULL, token = NULL)

Arguments

text

Character, text of message.

user

Character vector of screen names or user ids. See as_screenname() for more details.

media

File path to image or video media to be included in tweet.

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.

References

https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event


Posts status update to user's Twitter account

Description

[Deprecated]

Usage

post_tweet(
  status = "my first rtweet #rstats",
  media = NULL,
  token = NULL,
  in_reply_to_status_id = NULL,
  destroy_id = NULL,
  retweet_id = NULL,
  auto_populate_reply_metadata = FALSE,
  media_alt_text = NULL,
  lat = NULL,
  long = NULL,
  display_coordinates = FALSE
)

Arguments

status

Character, tweet status. Must be 280 characters or less.

media

Length 1 character vector with a file path to video media OR up-to length 4 character vector with file paths to static images to be included in tweet. The caller is responsible for managing this.

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.

in_reply_to_status_id

Status ID of tweet to which you'd like to reply. Note: in line with the Twitter API, this parameter is ignored unless the author of the tweet this parameter references is mentioned within the status text.

destroy_id

To delete a status, supply the single status ID here. If a character string is supplied, overriding the default (NULL), then a destroy request is made (and the status text and media attachments) are irrelevant.

retweet_id

To retweet a status, supply the single status ID here. If a character string is supplied, overriding the default (NULL), then a retweet request is made (and the status text and media attachments) are irrelevant.

auto_populate_reply_metadata

If set to TRUE and used with in_reply_to_status_id, leading @mentions will be looked up from the original Tweet, and added to the new Tweet from there. Defaults to FALSE.

media_alt_text

attach additional alt text metadata to the media you are uploading. Should be same length as media (i.e. as many alt text entries as there are media entries). See the official API documentation for more information.

lat

A numeric value representing the latitude of the location the tweet refers to. Range should be between -90 and 90 (north). Note that you should enable the "Precise location" option in your account via Settings and privacy > Privacy and Safety > Location. See the official Help Center section.

long

A numeric value representing the longitude of the location the tweet refers to. Range should be between -180 and 180 (west). See lat parameter.

display_coordinates

Put a pin on the exact coordinates a tweet has been sent from. Value should be TRUE or FALSE. This parameter would apply only if you have provided a valid lat/long pair of valid values.

References

Tweet: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-update Retweet: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-retweet-id Media: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create Alt-text: https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-metadata-create

See Also

tweet_post(), rtweet-deprecated

Other post: post_favorite(), post_follow(), post_friendship()


Rate limit helpers

Description

  • rate_limit() returns a tibble of info about all rate limits

  • rate_limit_reset() returns the next reset for a endpoint

  • rate_limit_wait() waits for the next reset for an endpoint

You should not need to use these function in the usual operation of rtweet because all paginated functions will wait on your behalf if you set retryonratelimit = TRUE.

Usage

rate_limit(resource_match = NULL, token = NULL)

rate_limit_reset(endpoint, token = NULL)

rate_limit_wait(endpoint, token = NULL)

Arguments

resource_match

An optional regular expression used to filter the resources listed in returned rate limit data.

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.

endpoint

Name of Twitter endpoint like "lookup/users", "/media/upload", or "/feedback/show/:id".

Details

[Deprecated]

References

https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status

See Also

rtweet-deprecated

Other tokens: create_token(), get_token()


Read comma separated value Twitter data.

Description

Reads Twitter data that was previously saved as a CSV file. [Deprecated]

Usage

read_twitter_csv(file, unflatten = FALSE)

Arguments

file

Name of CSV file.

unflatten

Logical indicating whether to unflatten (separate hasthags and mentions columns on space, converting characters to lists), defaults to FALSE.

Value

A tbl data frame of Twitter data

See Also

rtweet-deprecated

Other datafiles: flatten(), write_as_csv()


Expose errors of the response

Description

Expose errors of the response

Usage

retrieve_errors(expr = NULL)

Arguments

expr

An expression that might cause an error. If NULL it looks for the last error.

Examples

if (FALSE){
  new_rule <- stream_add_rule(list(value = "#rstats", tag = "rstats1"))
  stream_add_rule(list(value = "#rstats", tag = "rstats2")) # ERROR
  # See the full information provided by the API:
  retrieve_errors(stream_add_rule(list(value = "#rstats", tag = "rstats2")))
  retrieve_errors()
}

A generic function for rounding date and time values

Description

A generic function for rounding date and time values

Usage

round_time(x, n, tz)

Arguments

x

A vector of class POSIX or Date.

n

Unit to round to. Defaults to mins. Numeric values treated as seconds. Otherwise this should be one of "mins", "hours", "days", "weeks", "months", "years" (plural optional).

tz

Time zone to be used, defaults to "UTC" (Twitter default)

Value

If POSIXct then POSIX. If date then Date.

Examples

## class posixct
round_time(Sys.time(), "12 hours")

## class date
unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))

Client

Description

Set up your client mechanism for the Twitter API.

Usage

rtweet_client(client_id, client_secret, app, scopes = NULL)

Arguments

client_id, client_secret

Application OAuth client ID and client Secret. These are generally not required for rtweet_user() since the defaults will use the built-in rtweet app.

app

Name of the client, it helps if you make it match with the name of your app. On the Twitter app the Callback URI must be ⁠http://127.0.0.1:1410/⁠ (the trailing / must be included).

scopes

Default scopes allowed for users using this client. Leave NULL to allow everything or choose yours with set_scopes().

See Also

scopes

Examples

if (interactive()) {
  rtweet_client()
}

Authentication options

Description

Authenticate methods to use the Twitter API. See the instructions in vignette("auth", package = "rtweet").

Usage

rtweet_user(
  client_id = NULL,
  client_secret = NULL,
  api_key = client_id,
  api_secret = client_secret
)

rtweet_bot(api_key, api_secret, access_token, access_secret, app = "rtweet")

rtweet_app(bearer_token)

rtweet_bearer(client = NULL, scopes = NULL)

rtweet_oauth2(client = NULL, scopes = NULL)

Arguments

client_id, client_secret

Application OAuth client ID and client Secret. These are generally not required for rtweet_user() since the defaults will use the built-in rtweet app.

api_key, api_secret

API key and secret. Deprecated in favor of ⁠client_*⁠ arguments.

access_token, access_secret

Access token and secret.

app

Name of the application you are building.

bearer_token

App bearer token.

client

Which client app will be used, see rtweet_client() for details.

scopes

The permissions of the app, see set_scopes() for details. By default it uses the client's scopes. Provided here in case you want to modify them.

Details

There are four ways that you can authenticate with the Twitter API:

  • rtweet_user() interactively authenticates an existing Twitter user. This form is most appropriate if you want rtweet to control your Twitter account.

  • rtweet_app() authenticates as a Twitter application. An application can't perform actions (i.e. it can't tweet) but otherwise has generally higher rate limits (i.e. you can do more searches). See details at https://developer.twitter.com/en/docs/twitter-api/v1/rate-limits. This form is most appropriate if you are collecting data.

  • rtweet_bot() authenticates as bot that takes actions on behalf of an app. This form is most appropriate if you want to create a Twitter account that is run by a computer, rather than a human.

  • rtweet_oauth2() authenticates as a user using a client. This authentication is required in some endpoints.

To use rtweet_app(), rtweet_bot() or rtweet_oauth2() you will need to create your own Twitter app following the instructions in vignette("auth", package = "rtweet"). rtweet_user() can be used with your own app, but generally there is no need to because it uses the Twitter app provided by rtweet.

Use auth_as() to set the default auth mechanism for the current session, and auth_save() to save an auth mechanism for use in future sessions.

Value

If the validation is successful the OAuth token. For rtweet_app() a rtweet_bearer.

Security

All of the arguments to these functions are roughly equivalent to passwords so should generally not be typed into the console (where they the will be recorded in .Rhistory) or recorded in a script (which is easy to accidentally share). Instead, call these functions without arguments since the default behaviour is to use ask_pass that if possible uses askpass::askpass() to interactively safely prompt you for the values.

References

https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code

See Also

rtweet_client()

Other authentication: auth_as(), auth_get(), auth_save(), auth_setup_default()

Examples

## Not run: 
rtweet_app()

## End(Not run)

Deprecated functions in rtweet

Description

These functions might not work due to the drop of API v1 in favor of API v2.

  • clean_tweets(): No replacement.

  • collections(): No replacement (It hasn't worked for a while).

  • direct_messages(): No replacement.

  • do_call_rbind(): No replacement (if any it will be a method).

  • get_favorites(): Use tweet_liking_users().

  • get_followers(): Use user_following().

  • get_friends(): Use user_followers().

  • network_data() and network_graph(): No replacement.

  • list_memberships(): Use list_users().

  • get_mentions(): Use user_mentions()

  • user_block(): No replacement.

  • post_favorite(): No replacement.

  • post_list(): lists_subscribers(), list_subscriptions(), list_members(), lists_users()

  • post_tweet(): Use tweet_post().

  • post_follow(): No replacement.

  • post_destroy(): Use tweet_delete().

  • search_fullarchive(): Use tweet_search_all().

  • search_30d(): Use tweet_search_recent().

  • rate_limit(): No replacement (already implemented inside the calls).

  • save_as_csv(): No replacement.

  • search_tweets(): Use tweet_search_recent().

  • search_tweets2(): Use tweet_search_recent().

  • search_users(): Use user_search().

  • lookup_tweets(): Use tweet_get(), tweet_retweeted_by().

  • stream_tweets(): Use filtered_stream(), stream_add_rule(), stream_rm_rule() and sample_stream().

  • get_timeline(): Use user_timeline().

  • get_my_timeline(): Use user_timeline().

  • get_token(): Use auth_get().

  • get_tokens(): Use auth_get().

  • get_trends(): No replacement.

  • trends_available() and trends_closest(): No replacement.

  • ts_data() and ts_plot(): No replacement.

  • tweet_shot(): No replacement.

  • tweet_threading(): Use tweet_get() with conversation ID.


Extract the streaming rules

Description

Provides the information about the rules

Usage

rules(x, ...)

Arguments

x

An object returned by ⁠stream_*_rule⁠

...

Other arguments currently ignored.

See Also

stream_add_rule() and stream_rm_rule().


Premium Twitter searches

Description

Search 30day or fullarchive premium products. There is a limit of 5000 tweets and 25000 for the fullarchive and 30day endpoints respectively. In addition, there are some limits in the number of requests that are possible on a certain amount of time, this have already been taken into account. See the info provided by Twitter and the "Developer Account" section.

Usage

search_fullarchive(
  q,
  n = 100,
  fromDate = NULL,
  toDate = NULL,
  continue = NULL,
  env_name = NULL,
  premium = FALSE,
  safedir = NULL,
  parse = TRUE,
  token = NULL
)

search_30day(
  q,
  n = 100,
  fromDate = NULL,
  toDate = NULL,
  env_name = NULL,
  continue = NULL,
  premium = FALSE,
  safedir = NULL,
  parse = TRUE,
  token = NULL
)

Arguments

q

Search query on which to match/filter tweets. See details for information about available search operators.

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.

fromDate

Oldest date-time (YYYYMMDDHHMM) from which tweets should be searched for.

toDate

Newest date-time (YYYYMMDDHHMM) from which tweets should be searched for.

continue

A character string with the next results of a query. You must make the exact same query as the original, including q, toDate, and fromDate.

env_name

Name/label of developer environment to use for the search.

premium

A logical value if the environment is paid (TRUE) or sandboxed, the default (FALSE). It limits the number of results retrieved so the number of API queries needed to retrieve n results.

safedir

Name of directory to which each response object should be saved. If the directory doesn't exist, it will be created. If NULL (the default) then a dir will be created in the current working directory. To override/deactivate safedir set this to FALSE.

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.

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.

Details

Note: The env_name must match the ones you set up for the token you are using. [Deprecated]

Value

A tibble data frame of Twitter data.

Developer Account

Users must have an approved developer account and an active/labeled environment to access Twitter's premium APIs. For more information, to check your current Subscriptions and Dev Environments, or to apply for a developer account visit https://developer.twitter.com.

Search operators

Note: Bolded operators ending with a colon should be immediately followed by a word or quoted phrase (if appropriate)–e.g., lang:en

Keyword

  • "" ~~ match exact phrase

  • # ~~ hashtag

  • @ ~~ at mentions)

  • url: ~~ found in URL

  • lang: ~~ language of tweet

Accounts of interest

  • from: ~~ authored by

  • to: ~~ sent to

  • retweets_of: ~~ retweet author

Tweet attributes

  • is:retweet ~~ only retweets

  • has:mentions ~~ uses mention(s)

  • has:hashtags ~~ uses hashtags(s)

  • has:media ~~ includes media(s)

  • has:videos ~~ includes video(s)

  • has:images ~~ includes image(s)

  • has:links ~~ includes URL(s)

  • is:verified ~~ from verified accounts

Geospatial

  • bounding_box:[west_long south_lat east_long north_lat] ~~ lat/long coordinates box

  • point_radius:[lon lat radius] ~~ center of search radius

  • has:geo ~~ uses geotagging

  • place: ~~ by place

  • place_country: ~~ by country

  • has:profile_geo ~~ geo associated with profile

  • profile_country: ~~ country associated with profile

  • profile_region: ~~ region associated with profile

  • profile_locality: ~~ locality associated with profile

See Also

tweet_search_recent(), tweet_search_all(), rtweet-deprecated


Get tweets data on statuses identified via search query.

Description

Returns Twitter statuses matching a user provided search query. [Deprecated]

search_tweets2 Passes all arguments to search_tweets. Returns data from one OR MORE search queries. [Deprecated]

Usage

search_tweets(
  q,
  n = 100,
  type = c("mixed", "recent", "popular"),
  include_rts = TRUE,
  geocode = NULL,
  since_id = NULL,
  max_id = NULL,
  parse = TRUE,
  token = NULL,
  retryonratelimit = NULL,
  verbose = TRUE,
  ...
)

search_tweets2(...)

Arguments

q

Query to be searched, used to filter and select tweets to return from Twitter's REST API. Must be a character string not to exceed maximum of 500 characters. Spaces behave like boolean "AND" operator. To search for tweets containing at least one of multiple possible terms, separate each search term with spaces and "OR" (in caps). For example, the search q = "data science" looks for tweets containing both "data" and "science" located anywhere in the tweets and in any order. When "OR" is entered between search terms, query = "data OR science", Twitter's REST API should return any tweet that contains either "data" or "science." It is also possible to search for exact phrases using double quotes. To do this, either wrap single quotes around a search query using double quotes, e.g., q = '"data science"' or escape each internal double quote with a single backslash, e.g., ⁠q = "\"data science\""⁠.

Some other useful query tips:

  • Exclude retweets via "-filter:retweets"

  • Exclude quotes via "-filter:quote"

  • Exclude replies via "-filter:replies"

  • Filter (return only) verified via "filter:verified"

  • Exclude verified via "-filter:verified"

  • Get everything (firehose for free) via "-filter:verified OR filter:verified"

  • Filter (return only) tweets with links to news articles via "filter:news"

  • Filter (return only) tweets with media "filter:media"

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.

type

Character string specifying which type of search results to return from Twitter's REST API. The current default is type = "recent", other valid types include type = "mixed" and type = "popular".

include_rts

Logical, indicating whether to include retweets in search results. Retweets are classified as any tweet generated by Twitter's built-in "retweet" (recycle arrows) function. These are distinct from quotes (retweets with additional text provided from sender) or manual retweets (old school method of manually entering "RT" into the text of one's tweets).

geocode

Geographical limiter of the template "latitude,longitude,radius" e.g., geocode = "37.78,-122.40,1mi".

since_id

Supply a vector of ids or a data frame of previous results to find tweets newer than since_id.

max_id

Supply a vector of ids or a data frame of previous results to find tweets older than max_id.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

...

Further arguments passed as query parameters in request sent to Twitter's REST API. To return only English language tweets, for example, use lang = "en". For more options see Twitter's API documentation.

Details

Twitter API documentation recommends limiting searches to 10 keywords and operators. Complex queries may also produce API errors preventing recovery of information related to the query. It should also be noted Twitter's search API does not consist of an index of all Tweets. At the time of searching, the search API index includes between only 6-9 days of Tweets.

Value

List object with tweets and users each returned as a data frame.

A tbl data frame with additional "query" column.

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets

See Also

tweet_search_recent(), tweet_search_all(), rtweet-deprecated

tweet_search_recent(), rtweet-deprecated

Other tweets: get_favorites(), get_mentions(), get_timeline(), lists_statuses(), lookup_tweets()


Search for users

Description

Search for Twitter users. The Twitter API limits the results to at most 1,000 users. [Deprecated]

Usage

search_users(q, n = 100, parse = TRUE, token = NULL, verbose = TRUE)

Arguments

q

As string providing the search query. Try searching by interest, full name, company name, or location. Exact match searches are not supported.

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.

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.

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.

verbose

Show progress bars and other messages indicating current progress?

Value

Data frame with one row for each matching user.

References

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

See Also

user_search(), rtweet-deprecated

Other users: as_screenname(), lists_subscribers(), lookup_users()


Create fields

Description

Choose which fields are used, by default all are returned. Usually all the first 3 are accepted together and the last two too.

Usage

set_fields(
  media = media_fields,
  poll = poll_fields,
  tweet = tweet_fields,
  place = place_fields,
  user = user_fields,
  list = list_fields
)

Arguments

media

The fields you want from media_fields.

poll

The fields you want from poll_fields.

tweet

The fields you want from tweet_fields.

place

The fields you want from place_fields.

user

The fields you want from user_fields.

list

The fields you want from list_fields.

Value

A list with the fields requested ready to be used in your requests to the API.

See Also

Fields

Examples

set_fields()
set_fields(media = NULL)
set_fields(place = NULL, user = NULL)

Scopes of the OAuth2 token

Description

Permissions given to a token of a Twitter account. By default it allows everything.

Usage

set_scopes(read = TRUE, write = TRUE, tweet_moderate = TRUE, regenerate = TRUE)

Arguments

read

Allow to read.

write

Allow to write/manage?

tweet_moderate

Allow to hide or show replies to your Tweets.

regenerate

Allow to use the token for more than 2 hours.

Value

A character with all the possible scopes or those allowed.

References

https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code

Examples

set_scopes()

Defunct: Twitter stop words in multiple languages data.

Description

This data comes form a group of Twitter searches conducted at several times during the calendar year of 2017. The data are commonly observed words associated with 10 different languages, including c("ar", "en", "es", "fr", "in", "ja", "pt", "ru", "tr", "und"). Variables include "word" (potential stop words), "lang" (two or three word code), and "p" (probability value associated with frequency position along a normal distribution with higher values meaning the word occurs more frequently and lower values meaning the words occur less frequently).

Format

A tibble with three variables and 24,000 observations


Streaming

Description

Open a streaming connection with Twitter and stores tweets for as long as you wish.

Usage

filtered_stream(
  timeout,
  file = tempfile(),
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  append = TRUE,
  parse = TRUE
)

stream_add_rule(query, dry = FALSE, token = NULL)

stream_rm_rule(query, dry = FALSE, token = NULL)

sample_stream(
  timeout,
  file = tempfile(),
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  append = TRUE
)

Arguments

timeout

time, in seconds, of the recording stream.

file

Path to a file where the raw streaming should be stored.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

append

Append streaming to the file? Default does but it is recommended to have a new file for each call.

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.

query

If NULL returns the current rules, else depending:

  • In stream_add_rule it should be a list of value and tag.

  • In stream_rm_rule it should be a vector of ids of rules to be removed

dry

Check if the addition or removal of the rule works.

Details

The connection can be left open as long as you wish, the data is appended to the file provided. Be aware that the stream might have incomplete records (you won't be able to read directly from the json file). One tweet might belong to multiple rules.

Value

The records in the streaming.

Functions

  • filtered_stream(): Start a filtered stream according to the rules.

  • stream_add_rule(): Add rules for the filtered streaming.

  • stream_rm_rule(): Remove rules from the filtered streaming

  • sample_stream(): Retrieve a sample of the tweets posted.

See Also

Rules for filtered stream: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/build-a-rule

Sampled stream: https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream

Filtered stream: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream

ids()

Examples

# Requires a bearer token
if (FALSE) {
  # How many rules do we have
  stream_add_rule(NULL)
  # Add new rule
  new_rule <- stream_add_rule(list(value = "#rstats", tag = "rstats"))
  new_rule
  # Open filtered streaming connection for 30s
  filtered_stream(file = tempfile(), timeout = 30, parse = FALSE)
  # Remove rule
  stream_rm_rule(ids(new_rule))
  # Open random streaming connection
  sample_stream(file = tempfile(), timeout = 3, parse = FALSE)
}

Collect a live stream of Twitter data

Description

Streams public statuses to a file via one of the following four methods:

  1. Sampling a small random sample of all publicly available tweets

  2. Filtering via a search-like query (up to 400 keywords)

  3. Tracking via vector of user ids (up to 5000 user_ids)

  4. Location via geo coordinates (1-360 degree location boxes)

Learn more in vignette("stream", package = "rtweet")

Usage

stream_tweets(
  q = "",
  timeout = 30,
  parse = TRUE,
  token = NULL,
  file_name = NULL,
  verbose = TRUE,
  append = TRUE,
  ...
)

Arguments

q

Query used to select and customize streaming collection method. There are four possible methods:

  1. The default, q = "", returns a small random sample of all publicly available Twitter statuses.

  2. To filter by keyword, provide a comma separated character string with the desired phrase(s) and keyword(s).

  3. Track users by providing a comma separated list of user IDs or screen names.

  4. Use four latitude/longitude bounding box points to stream by geo location. This must be provided via a vector of length 4, e.g., c(-125, 26, -65, 49).

timeout

Integer specifying number of seconds to stream tweets for. Stream indefinitely with timeout = Inf.

The stream can be interrupted at any time, and file_name will still be valid file.

parse

Use FALSE to opt-out of parsing the tweets.

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.

file_name

Character with name of file. If not specified, will write to a temporary file stream_tweets*.json.

verbose

If TRUE, display a progress bar.

append

If TRUE, will append to the end of file_name; if FALSE, will overwrite.

...

Other arguments passed in to query parameters.

Details

[Deprecated]

Value

A tibble with one row per tweet

References

They were removed from the website.

The webpages describing how it used to work were removed.

See Also

filtered_stream(), rtweet-deprecated


Count tweets

Description

Count tweets

Usage

tweet_counts_recent(query, ..., token = NULL, parse = TRUE, verbose = FALSE)

tweet_counts_all(query, ..., token = NULL, parse = TRUE, verbose = FALSE)

Arguments

query

One query for matching Tweets.

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

Value

The number of tweets for a given granularity

References

https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all

https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-recent

Examples

if (FALSE) {
  tcr <- tweet_counts_recent(query = "#rtweet", parse = FALSE)
  tca <- tweet_counts_all(query = "#rtweet", parse = FALSE)
}

Delete tweet

Description

Will delete a tweet

Usage

tweet_delete(id, verbose = FALSE, token = NULL)

Arguments

id

At least a tweet id.

verbose

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

token

This endpoint accepts a OAuth2.0 authentication (can be created via rtweet_oauth2()) or a bearer token (can be created via rtweet_app()).

References

https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/delete-tweets-id

See Also

tweet_post(), tweet_search_recent(), user_timeline()


Create a Tweet Embed

Description

Twitter API GET call to retieve the tweet in embedded form.

Usage

tweet_embed(screen_name, status_id, ...)

Arguments

screen_name

character, screen name of the user

status_id

character, status id

...

parameters to pass to the GET call. See https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/get-statuses-oembed for details.

Value

character

See Also

httr::GET(),httr::content()

Examples

name   <- 'kearneymw'
status <- '1087047171306856451'

tweet_embed(screen_name = name, status_id = status)

tweet_embed(
 screen_name = name,
 status_id = status,
 hide_thread = TRUE, 
 hide_media = FALSE, 
 align = 'center'
)

Get tweet information

Description

Look up tweets up to 100 at the same time.

Usage

tweet_get(
  id,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

At least a tweet id.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

This endpoint accepts a OAuth2.0 authentication (can be created via rtweet_oauth2()) or a bearer token (can be created via rtweet_app()).

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

References

One tweet: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id

Multiple tweets: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets

See Also

lookup_tweets()

Examples

if (FALSE){
 tweet_get("567053242429734913", parse = FALSE)
 tweet_get(c("567053242429734913", "567053242429734913"), parse = FALSE)
 tweet_get(c("567053242429734913", "567053242429734913"), parse = TRUE)
}

Liking users

Description

Looks up who have liked a given tweet.

Usage

tweet_liking_users(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A tweet id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users

Examples

if (FALSE) {
  tlu <- tweet_liking_users("567053242429734913", n = Inf, verbose = TRUE)
}

Post a tweet

Description

This function uses the API v2 to post tweets.

Usage

tweet_post(text, ..., token = NULL)

Arguments

text

Text of the tweet.

...

Other accepted arguments.

token

This endpoint accepts a OAuth2.0 authentication (can be created via rtweet_oauth2()) or a bearer token (can be created via rtweet_app()).

References

https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets

Examples

if (FALSE) {
 # It requires the Oauth2.0 Authentication
  tp_id <- tweet_post("Posting from #rtweet with the basic plan")
  tweet_post()
}

Get quoted tweet information

Description

Look up tweets quoting that tweet id.

Usage

tweet_quoted(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

At least a tweet id.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

This endpoint accepts a OAuth2.0 authentication (can be created via rtweet_oauth2()) or a bearer token (can be created via rtweet_app()).

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

References

One tweet: https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets

Examples

if (FALSE){
 tweet_quoted("1631945769748930561", parse = FALSE)
}

Tweet retweeted by

Description

Looks up who have retweeted a given tweet.

Usage

tweet_retweeted_by(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A tweet id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

Value

A data.frame with the user information of who retweeted it: id, name, and username. Other information depends on the expansions and fields requested.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/get-tweets-id-retweeted_by

Examples

if (FALSE) {
  rb <- tweet_retweeted_by("567053242429734913")
}

Search in the Twitter archive

Description

Search in the Twitter archive

Usage

tweet_search_all(
  query,
  n = 500,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

query

One query for matching Tweets.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

Note

OAuth2.0 requires tweet.read and users.read permissions.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all

Examples

if (FALSE) {
  sa <- tweet_search_all("#rtweet", parse = FALSE)
}

Search recent tweets

Description

Look up tweets from the last seven days that match a search query.

Usage

tweet_search_recent(
  query,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

query

One query for matching Tweets.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about the paginated queries (if any) and to store the data of each page.

Note

OAuth2.0 requires tweet.read and users.read permissions.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent

Examples

if (FALSE) {
  sr <- tweet_search_recent("#rtweet", sort_order = "relevancy", parse = FALSE)
}

Capture an image of a tweet/thread

Description

Provide a status id or a full Twitter link to a tweet and this function will capture an image of the tweet — or tweet + thread (if there are Twitter-linked replies) — from the mobile version of said tweet/thread. [Deprecated]

Usage

tweet_shot(statusid_or_url, zoom = 3, scale = TRUE)

Arguments

statusid_or_url

a valid Twitter status id (e.g. "947082036019388416") or a valid Twitter status URL (e.g. "⁠https://twitter.com/jhollist/status/947082036019388416⁠").

zoom

a positive number >= 1. See the help for ⁠[webshot::webshot()]⁠ for more information.

scale

auto-scale the image back to 1:1? Default it TRUE, which means magick will be used to return a "normal" sized tweet. Set it to FALSE to perform your own image manipulation.

Details

For this to work, you will need to ensure the packages in ⁠Suggests:⁠ are installed as they will be loaded upon the first invocation of this function.

Use the zoom factor to get more pixels which may improve the text rendering of the tweet/thread.

Value

magick object

See Also

rtweet-deprecated

Examples

## Not run: 
if (auth_has_default()) {
    shot1 <- tweet_shot("947061504892919808")
    plot(shot1)
    shot2 <- tweet_shot("https://twitter.com/ma_salmon/status/947061504892919808")
    plot(shot2)
}

## End(Not run)

Collect statuses contained in a thread

Description

Return all statuses that are part of a thread (Replies from a user to their own tweets). By default the function traverses first backwards from the origin status_id of the thread up to the root, then checks if there are any child statuses that were posted after the origin status. [Deprecated]

Usage

tweet_threading(tw, traverse = c("backwards", "forwards"), verbose = FALSE)

Arguments

tw

lookup_tweets() output containing at least the last status in the thread or an id of a tweet.

traverse

character, direction to traverse from origin status in tw. It is not recommended to change the default if you don't know at which point of a thread you are starting.

verbose

logical, output to console status of traverse.

Details

The backwards method looks up the tweet which is replying to, so it works if starting from the last tweet of the thread.

The forwards method looks for newer replies to the tweet provided. If the tweet doesn't have a reply it won't be able to find anything. The forwards method is limited by the timeline API (See get_timeline()).

Value

Tweets in a structure like lookup_tweets().

See Also

rtweet-deprecated, lookup_tweets()


Parsing data into tweets/users data tibbles

Description

For internal use only

Usage

tweets_with_users(x)

users_with_tweets(x)

Arguments

x

A list of responses, with one element for each page.

Value

A tweets/users tibble with users/tweets attribute.


Blocking or unblocking twitter users

Description

user_block(...) blocks or unblocks a target twitter user. user_unblock(...) is synonymous to user_block(..., unblock=TRUE). [Deprecated]

Usage

user_block(user, unblock = FALSE, token = NULL)

user_unblock(user, token = NULL)

Arguments

user

Character vector of screen names or user ids. See as_screenname() for more details.

unblock

Logical indicating whether to unblock the intended friend.

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.

References

Block: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create

See Also

rtweet-deprecated


Find users blocked.

Description

List of users that are blocked.

Usage

user_blocked(
  id,
  n = 1000,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A user id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking

Examples

if (FALSE) {
  uf <- user_blocked("1599030512919650304", verbose = TRUE)
}

Retrieve user bookmarks

Description

Collects the 800 most recent bookmarked tweets of a user.

Usage

user_bookmarks(
  id,
  n = 100,
  ...,
  expansions = NULL,
  fields = NULL,
  parse = TRUE,
  token = NULL,
  verbose = FALSE
)

Arguments

id

Twitter user id: character string identifying your account.

n

Number of tweets to retrieve.

...

Other arguments passed down to the API.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

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.

token

This endpoint only accept a OAuth2.0 authentication (can be created via rtweet_oauth2()).

verbose

A logical value

Value

A data.frame with the user information of who is following the list: edit_history_tweet_ids, id and text. Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(list = NULL).

  • Fields: set_fields(list = NULL).

Note

This endpoint requires a OAuth2.0 authentication, with tweet.read, users.read and bookmark.read permissions.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks

See Also

rtweet_oauth2(), user_self()

Examples

if (FALSE) {
   # Requires token_oa2
   ub <- user_bookmarks(user_self()$id, parse = FALSE, n = Inf, token = token_oa2)
}

Search users by username

Description

Looks up users by their username.

Usage

user_by_username(
  username,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

username

A user name string or up to 100.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by

See Also

user_search()

Examples

if (FALSE) {
  user_by_username("rOpenSci")
  user_by_username(c("Bioconductor", "R_Contributors"))
}

Find followers.

Description

List of users that follow the specified user ID.

Usage

user_followers(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A user id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers

Examples

if (FALSE) {
  uf <- user_followers("1599030512919650304", verbose = TRUE)
}

Find which users are being followed.

Description

List of users the specified user ID is following.

Usage

user_following(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A user id string.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following

Examples

if (FALSE) {
  uf <- user_following("1599030512919650304", verbose = TRUE)
}

Liked tweets from a user

Description

Looks up tweets liked by a user.

Usage

user_liked_tweets(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A tweet id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets

Examples

if (FALSE) {
  ult <- user_liked_tweets("1599030512919650304", verbose = TRUE)
}

Lists a specified user follows

Description

Looks up lists a user follows.

Usage

user_list_follows(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers

Examples

if (FALSE) {
  ulf <- user_list_follows("1051050384")
}

Search users by username

Description

Looks up users by their username.

Usage

user_lists(
  ids,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A user name string or up to 100.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists

Examples

if (FALSE) {
  ul <- user_lists("1051050384")
}

Tweets mentioning a user

Description

Looks up to 800 tweets mentioning a user.

Usage

user_mentions(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A user id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions

Examples

if (FALSE) {
  um <- user_mentions("1599030512919650304", verbose = TRUE)
}

List muted users

Description

Looks up the muted users.

Usage

user_muted(
  ids,
  n = 1000,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

ids

A list id.

n

Number of users to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other parameters passed to the body of the request.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the user information of who is following the list: id, name, and username. Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, list = NULL).

  • Fields: set_fields(media = NULL, poll = NULL, place = NULL, list = NULL).

References

https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting

See Also

user_self()

Examples

if (FALSE) {
  um <- user_muted(user_self()$id)
}

Tweets from a user

Description

Looks up tweets posted by a user.

Usage

user_self(
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

Value

A data.frame with the id, name and username of the authenticated user. Other information depends on the expansions and fields requested. Accepted values are:

  • Expansions: set_expansions(tweet = NULL, list = NULL).

  • Fields: set_fields(media = NULL, poll = NULL, place = NULL)

References

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me

Examples

if (FALSE) {
  me <- user_self()
}

User timeline

Description

Looks up the timeline of a user with up to 800 tweets in the last 7 days.

Usage

user_timeline(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A tweet id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions

Examples

if (FALSE) {
  ut <- user_timeline("1599030512919650304", verbose = TRUE)
}

Tweets from a user

Description

Looks up tweets posted by a user.

Usage

user_tweets(
  id,
  n = 100,
  expansions = NULL,
  fields = NULL,
  ...,
  token = NULL,
  parse = TRUE,
  verbose = FALSE
)

Arguments

id

A user id string.

n

Number of tweets to query.

expansions

Set NULL to not use any expansion, set NA to get all expansions, or provide a vector with the expansions you want (create it with set_expansions()).

fields

Set NULL to not use any field, get all allowed fields with NA, provide a list with the fields you want (create it with set_fields()).

...

Other arguments passed to the API.

token

These endpoints only accept a bearer token (can be created via rtweet_app()). In most cases you are better of changing the default for all calls via auth_as().

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

A logical value to provide more information about paginated queries.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets

Examples

if (FALSE) {
  ut <- user_tweets("1599030512919650304", verbose = TRUE)
}

Get tweets from users, or users from tweets

Description

Twitter API endpoints that return tweets also return data about the users who tweeted, and most endpoints that return users also return their last tweet. Showing these additional columns would clutter the default display, so rtweet instead stores in special attributes and allows you to show them with the user_data() and tweets_data() helpers.

Usage

users_data(tweets)

tweets_data(users)

Arguments

tweets

A data frame of tweets.

users

A data frame of users.

Value

user_data() returns a data frame of users; tweets_data() returns a data frame of tweets.


Save Twitter data as a comma separated value file.

Description

Saves as flattened CSV file of Twitter data.

Usage

write_as_csv(x, file_name, prepend_ids = TRUE, na = "", fileEncoding = "UTF-8")

save_as_csv(x, file_name, prepend_ids = TRUE, na = "", fileEncoding = "UTF-8")

Arguments

x

Data frame returned by an rtweet function.

file_name

Desired name to save file as. If file_name does not include the extension ".csv" it will be added automatically.

prepend_ids

Logical indicating whether to prepend an "x" before all Twitter IDs (for users, statuses, lists, etc.). It's recommended when saving to CSV as these values otherwise get treated as numeric and as a result the values are often less precise due to rounding or other class-related quirks. Defaults to true.

na

Value to be used for missing (NA)s. Defaults to empty character, "".

fileEncoding

Encoding to be used when saving to CSV. defaults to "UTF-8".

Value

Saved CSV files in current working directory.

See Also

Other datafiles: flatten(), read_twitter_csv()

Other datafiles: flatten(), read_twitter_csv()