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 |
Built: | 2024-11-21 06:30:49 UTC |
Source: | CRAN |
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.
as_screenname(x)
as_screenname(x)
x |
A character vector of Twitter screen names. |
Other users:
lists_subscribers()
,
lookup_users()
,
search_users()
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.
auth_as(auth = NULL)
auth_as(auth = NULL)
auth |
One of the following options:
|
Invisibly returns the previous authentication mechanism.
auth_sitrep()
to help finding and managing authentications.
Other authentication:
auth_get()
,
auth_save()
,
auth_setup_default()
,
rtweet_user()
## 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)
## 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)
If there is a file with saved tokens it will delete it.
auth_clean(old = TRUE, new = FALSE)
auth_clean(old = TRUE, new = FALSE)
old |
A logical value if you want to remove old tokens. |
new |
A logical value if you want to remove new tokens. |
This functions helps to comply with CRAN policy to remove files created by the package.
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.
auth_clean(TRUE, TRUE)
auth_clean(TRUE, TRUE)
If no authentication has been set up for this session, auth_get()
will
call auth_as()
to set it up.
auth_get()
auth_get()
The current token used.
Other authentication:
auth_as()
,
auth_save()
,
auth_setup_default()
,
rtweet_user()
## Not run: auth_get() ## End(Not run)
## Not run: auth_get() ## End(Not run)
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.
auth_save(auth, name) auth_list()
auth_save(auth, name) auth_list()
auth |
One of |
name |
Name of the file to use. |
The tokens are saved on tools::R_user_dir("rtweet", "config")
.
Invisible the path where the authentication is saved.
auth_sitrep()
to help finding and managing authentications.
Other authentication:
auth_as()
,
auth_get()
,
auth_setup_default()
,
rtweet_user()
## 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)
## 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)
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.
auth_setup_default() auth_has_default()
auth_setup_default() auth_has_default()
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.
auth_setup_default()
: Invisibly returns the previous authentication mechanism.
auth_has_default()
: A logical value TRUE
if there is a default authentication.
Other authentication:
auth_as()
,
auth_get()
,
auth_save()
,
rtweet_user()
## Not run: if (!auth_has_default() && interactive()) { auth_setup_default() } ## End(Not run)
## Not run: if (!auth_has_default() && interactive()) { auth_setup_default() } ## End(Not run)
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.
auth_sitrep()
auth_sitrep()
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.
Invisibly, TRUE if some problems were found and FALSE otherwise
It is safe to use in public, as instead of the tokens or keys it reports a letter.
auth_sitrep()
auth_sitrep()
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.
clean_tweets(x, clean = c("users", "hashtags", "urls", "media"))
clean_tweets(x, clean = c("users", "hashtags", "urls", "media"))
x |
Tweets |
clean |
Type of elements to be removed. |
A vector with the text without the entities selected
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.
client_as(client = NULL)
client_as(client = NULL)
client |
One of the following options:
|
Invisibly returns the previous authentication mechanism.
Other client:
client_get()
,
client_has_default()
,
client_save()
## 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)
## 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)
Removes the rtweet clients directory.
client_clean()
client_clean()
Either TRUE if folder could be deleted or FALSE.
client_clean()
client_clean()
If no client has been set up for this session, client_get()
will
call client_as()
to set it up.
client_get()
client_get()
The current client used.
Other client:
client_as()
,
client_has_default()
,
client_save()
## Not run: client_get() ## End(Not run)
## Not run: client_get() ## End(Not run)
You'll need to run this function once per computer so that rtweet can use your client.
client_has_default() client_setup_default()
client_has_default() client_setup_default()
It will use the current default account for rtweet and save them as "rtweet". If a default is found it will use it instead.
client_setup_default()
: Invisibly returns the previous authentication mechanism.
client_has_default()
: A logical value TRUE
if there is a default authentication.
Other client:
client_as()
,
client_get()
,
client_save()
## Not run: if (!client_has_default()) { client_setup_default() } ## End(Not run)
## Not run: if (!client_has_default()) { client_setup_default() } ## End(Not run)
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.
client_save(client) client_list()
client_save(client) client_list()
client |
A client |
The tokens are saved on the clients folder in tools::R_user_dir("rtweet", "config")
.
Invisible the path where the client is saved.
auth_sitrep()
to help finding and managing authentications.
Other client:
client_as()
,
client_get()
,
client_has_default()
## 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)
## 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)
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.
direct_messages( n = 50, cursor = NULL, next_cursor = NULL, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
direct_messages( n = 50, cursor = NULL, next_cursor = NULL, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
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 |
|
parse |
If |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
verbose |
Show progress bars and other messages indicating current progress? |
A list with one element for each page of results.
## Not run: ## get my direct messages direct_messages() ## End(Not run)
## Not run: ## get my direct messages direct_messages() ## End(Not run)
Row bind lists of tweets/users data whilst also preserving and binding users/tweets attribute data.
do_call_rbind(x)
do_call_rbind(x)
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). |
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.
This data comes from "Unicode.org": https://unicode.org/emoji/charts/full-emoji-list.html. The data are codes and descriptions of Emojis.
A tibble with two variables and 2,623 observations.
Extract entities of the tweets linked to a tweet id.
entity(x, entity, ...)
entity(x, entity, ...)
x |
A tweets object of the rtweet package. |
entity |
A entity to extract data from. |
... |
Other possible arguments currently ignored. |
The position of where does this occur is not provided.
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")
Twitter parameters to add more fields on the returned values.
set_expansions( tweet = tweet_expansions(), user = user_expansions(), list = list_expansions() ) tweet_expansions(attachments = TRUE, referenced_tweets = TRUE) user_expansions() list_expansions()
set_expansions( tweet = tweet_expansions(), user = user_expansions(), list = list_expansions() ) tweet_expansions(attachments = TRUE, referenced_tweets = TRUE) user_expansions() list_expansions()
tweet , user , list
|
|
attachments |
Add attachments values? Default yes. |
referenced_tweets |
Add referenced_tweets values? Default yes. |
The set_expansions
can be used to prepare the arguments for other rtweet functions.
A character with the characters of valid expansions.
https://developer.twitter.com/en/docs/twitter-api/expansions
tweet_expansions() user_expansions() set_expansions()
tweet_expansions() user_expansions() set_expansions()
Arguments of expansion that select which values are returned. Fields are possible for:
media_fields place_fields poll_fields list_fields tweet_fields user_fields metrics_fields
media_fields place_fields poll_fields list_fields tweet_fields user_fields metrics_fields
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.
https://developer.twitter.com/en/docs/twitter-api/fields
media_fields place_fields poll_fields tweet_fields user_fields
media_fields place_fields poll_fields tweet_fields user_fields
Converts list columns that containing all atomic elements into character vectors and vice versa (for appropriate named variables according to the rtweet package)
flatten(x) unflatten(x)
flatten(x) unflatten(x)
x |
Data frame with list columns or converted-to-character (flattened) columns. |
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
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.
Other datafiles:
read_twitter_csv()
,
write_as_csv()
Other datafiles:
read_twitter_csv()
,
write_as_csv()
Returns up to 3,000 tweets liked/favorited for each user
.
get_favorites( user, n = 200, since_id = NULL, max_id = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
get_favorites( user, n = 200, since_id = NULL, max_id = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
user |
Character vector of screen names or user ids.
See |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
since_id |
Supply a vector of ids or a data frame of previous results to
find tweets newer than |
max_id |
Supply a vector of ids or a data frame of previous results to
find tweets older than |
parse |
If |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
A tibble with one row for each tweet.
Other tweets:
get_mentions()
,
get_timeline()
,
lists_statuses()
,
lookup_tweets()
,
search_tweets()
if (FALSE) { get_favorites("KFC") }
if (FALSE) { get_favorites("KFC") }
Returns a list of user IDs for the accounts following specified user.
get_followers( user, n = 5000, cursor = "-1", retryonratelimit = NULL, parse = TRUE, verbose = TRUE, token = NULL, page = lifecycle::deprecated() )
get_followers( user, n = 5000, cursor = "-1", retryonratelimit = NULL, parse = TRUE, verbose = TRUE, token = NULL, page = lifecycle::deprecated() )
user |
Character vector of screen names or user ids.
See |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
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 If you expect a query to take hours or days to perform, you should not
rely solely on |
parse |
If |
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 |
page |
A tibble data frame with one column named "from_id" with the followers and another one "to_id" with the user used as input.
if (FALSE) { users <- get_followers("_R_Foundation") }
if (FALSE) { users <- get_followers("_R_Foundation") }
Returns a list of user IDs for the accounts following BY one or more specified users.
get_friends( users, n = 5000, retryonratelimit = NULL, cursor = "-1", parse = TRUE, verbose = TRUE, token = NULL, page = lifecycle::deprecated() )
get_friends( users, n = 5000, retryonratelimit = NULL, cursor = "-1", parse = TRUE, verbose = TRUE, token = NULL, page = lifecycle::deprecated() )
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 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 You are not guaranteed to get exactly |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
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 |
page |
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).
A tibble data frame with two columns, "from_id" for name or ID of target user and "to_id" for accounts ID they follow.
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
.
if (FALSE) { get_friends("ropensci") }
if (FALSE) { get_friends("ropensci") }
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.
get_mentions( n = 200, since_id = NULL, max_id = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL, ... )
get_mentions( n = 200, since_id = NULL, max_id = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL, ... )
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
since_id |
Supply a vector of ids or a data frame of previous results to
find tweets newer than |
max_id |
Supply a vector of ids or a data frame of previous results to
find tweets older than |
parse |
If |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
... |
Other arguments passed as parameters in composed API query. |
Tibble of mentions data.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/overview
Other tweets:
get_favorites()
,
get_timeline()
,
lists_statuses()
,
lookup_tweets()
,
search_tweets()
get_retweets()
returns the 100 most recent retweets of a tweet;
get_retweeters()
returns the 100 most recent users who retweeted them.
get_retweets(status_id, n = 100, parse = TRUE, token = NULL, ...) get_retweeters(status_id, n = 100, parse = TRUE, token = NULL)
get_retweets(status_id, n = 100, parse = TRUE, token = NULL, ...) get_retweeters(status_id, n = 100, parse = TRUE, token = NULL)
status_id |
Tweet/status id. |
n |
Number of results to retrieve. Must be <= 100. |
parse |
If |
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 |
... |
Other arguments used as parameters in the query sent to
Twitter's rest API, for example, |
Tweets data of the most recent retweets/retweeters of a given status.
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).
At most up to 3,200 of a user's most recent Tweets can be retrieved.
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, ... )
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, ... )
user |
Character vector of screen names or user ids.
See |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
since_id |
Supply a vector of ids or a data frame of previous results to
find tweets newer than |
max_id |
Supply a vector of ids or a data frame of previous results to
find tweets older than |
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 |
check |
|
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
... |
Further arguments passed on as parameters in API query. |
A tbl data frame of tweets data with users data attribute.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/overview
user_timeline()
, rtweet-deprecated
Other tweets:
get_favorites()
,
get_mentions()
,
lists_statuses()
,
lookup_tweets()
,
search_tweets()
Please use auth_get()
instead.
get_token() get_tokens()
get_token() get_tokens()
Other tokens:
create_token()
,
rate_limit()
get_trends( woeid = 1, lat = NULL, lng = NULL, exclude_hashtags = FALSE, token = NULL, parse = TRUE )
get_trends( woeid = 1, lat = NULL, lng = NULL, exclude_hashtags = FALSE, token = NULL, parse = TRUE )
woeid |
Numeric, WOEID (Yahoo! Where On Earth ID) or character
string of desired town or country. Users may also supply latitude
and longitude coordinates to fetch the closest available trends
data given the provided location. Latitude/longitude coordinates
should be provided as WOEID value consisting of 2 numeric values
or via one latitude value and one longitude value (to the
appropriately named parameters). To browse all available trend
places, see |
lat |
Optional alternative to WOEID. Numeric, latitude in degrees. If two coordinates are provided for WOEID, this function will coerce the first value to latitude. |
lng |
Optional alternative to WOEID. Numeric, longitude in degrees. If two coordinates are provided for WOEID, this function will coerce the second value to longitude. |
exclude_hashtags |
Logical, indicating whether or not to exclude hashtags. Defaults to FALSE–meaning, hashtags are included in returned trends. |
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 |
parse |
If |
Tibble data frame of trends data for a given geographical area.
Other trends:
trends_available()
Extract the ids of the rtweet data if present. Depending on the object type it returns either users ids, tweet ids or rules ids.
ids(x, ...)
ids(x, ...)
x |
An object of the rtweet package. |
... |
Other arguments currently unused. |
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.
A tibble with five variables and 486 observations.
Appends parsed Twitter data with latitude and longitude variables using all available geolocation information.
lat_lng( x, coords = c("coords_coords", "bbox_coords", "geo_coords"), prefs = "bbox_coords" )
lat_lng( x, coords = c("coords_coords", "bbox_coords", "geo_coords"), prefs = "bbox_coords" )
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 |
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.
Returns updated data object with full information latitude and longitude vars.
Other geo:
lookup_coords()
create the links from the rtweet data present. Depending on the object type it returns either users links, tweet links or rules links.
links(x, ...)
links(x, ...)
x |
An object of the rtweet package. |
... |
Other arguments currently unused. |
Looks up the followers of a list.
list_followers( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
list_followers( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
if (FALSE) { lf <- list_followers("1150793074420998146") }
if (FALSE) { lf <- list_followers("1150793074420998146") }
Looks up information about a list.
list_get( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
list_get( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id
if (FALSE) { lg <- list_get("1306285118877831168") }
if (FALSE) { lg <- list_get("1306285118877831168") }
Looks up the users of a list.
list_members( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
list_members( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id
if (FALSE) { lm <- list_members("1306285118877831168") }
if (FALSE) { lm <- list_members("1306285118877831168") }
Lists a specified user is a member of.
list_membership( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
list_membership( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id
if (FALSE) { lm <- list_membership("20815041") }
if (FALSE) { lm <- list_membership("20815041") }
Looks up the followers of a list.
list_tweets( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
list_tweets( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
if (FALSE) { lt <- list_tweets("1150793074420998146") }
if (FALSE) { lt <- list_tweets("1150793074420998146") }
Get Twitter list members (users on a given list).
lists_members( list_id = NULL, slug = NULL, owner_user = NULL, n = 5000, cursor = "-1", token = NULL, retryonratelimit = NULL, verbose = TRUE, parse = TRUE, ... )
lists_members( list_id = NULL, slug = NULL, owner_user = NULL, n = 5000, cursor = "-1", token = NULL, retryonratelimit = NULL, verbose = TRUE, parse = TRUE, ... )
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 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 You are not guaranteed to get exactly |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
verbose |
Show progress bars and other messages indicating current progress? |
parse |
If |
... |
Other arguments used as parameters in query composition. |
Other lists:
lists_statuses()
,
lists_subscribers()
,
lists_subscriptions()
,
lists_users()
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.
lists_memberships( user = NULL, n = 200, cursor = "-1", filter_to_owned_lists = FALSE, token = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, previous_cursor = NULL )
lists_memberships( user = NULL, n = 200, cursor = "-1", filter_to_owned_lists = FALSE, token = NULL, parse = TRUE, retryonratelimit = NULL, verbose = TRUE, previous_cursor = NULL )
user |
Character vector of screen names or user ids.
See |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
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 |
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 |
parse |
If |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
verbose |
Show progress bars and other messages indicating current progress? |
previous_cursor |
Get a timeline of tweets authored by members of a specified list.
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 )
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 )
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 |
max_id |
Supply a vector of ids or a data frame of previous results to
find tweets older than |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
data
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.
lists_subscribers( list_id = NULL, slug = NULL, owner_user = NULL, n = 5000, cursor = "-1", parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
lists_subscribers( list_id = NULL, slug = NULL, owner_user = NULL, n = 5000, cursor = "-1", parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
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 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 You are not guaranteed to get exactly |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
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.
lists_subscriptions( user, n = 20, cursor = "-1", parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
lists_subscriptions( user, n = 20, cursor = "-1", parse = TRUE, retryonratelimit = NULL, verbose = TRUE, token = NULL )
user |
Character vector of screen names or user ids.
See |
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
Other lists:
lists_members()
,
lists_statuses()
,
lists_subscribers()
,
lists_users()
Get all lists a specified user subscribes to, including their own.
lists_users(user = NULL, reverse = FALSE, token = NULL, parse = TRUE)
lists_users(user = NULL, reverse = FALSE, token = NULL, parse = TRUE)
user |
Character vector of screen names or user ids.
See |
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 |
parse |
If |
data
Other lists:
lists_members()
,
lists_statuses()
,
lists_subscribers()
,
lists_subscriptions()
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.
lookup_coords(address, components = NULL, apikey = NULL, ...)
lookup_coords(address, components = NULL, apikey = NULL, ...)
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, |
... |
Additional arguments passed as parameters in the HTTP request |
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.
Object of class coords.
Other geo:
lat_lng()
## 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)
## 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)
Gets information on friendship between two Twitter users.
lookup_friendships(source, target, parse = TRUE, token = NULL)
lookup_friendships(source, target, parse = TRUE, token = NULL)
source |
Screen name or user id of source user. |
target |
Screen name or user id of target user. |
parse |
If |
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 |
Other friends:
my_friendships()
lookup_tweets( statuses, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
lookup_tweets( statuses, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
statuses |
User id or screen name of target user. |
parse |
If |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
verbose |
Show progress bars and other messages indicating current progress? |
A tibble of tweets data.
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).
lookup_users( users, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
lookup_users( users, parse = TRUE, token = NULL, retryonratelimit = NULL, verbose = TRUE )
users |
User id or screen name of target user. |
parse |
If |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
verbose |
Show progress bars and other messages indicating current progress? |
A tibble of users data.
Other users:
as_screenname()
,
lists_subscribers()
,
search_users()
if (FALSE) { users <- c("twitter", "rladiesglobal", "_R_Foundation") users <- lookup_users(users) }
if (FALSE) { users <- c("twitter", "rladiesglobal", "_R_Foundation") users <- lookup_users(users) }
Gets information on friendship between authenticated user and up to 100 other users.
my_friendships(user, parse = FALSE, token = NULL)
my_friendships(user, parse = FALSE, token = NULL)
user |
Character vector of screen names or user ids.
See |
parse |
If |
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 |
Other friends:
lookup_friendships()
network_data()
returns a data frame that can easily be converted to
various network classes.
network_graph()
returns a igraph object
network_data(x, e = c("mention", "retweet", "reply", "quote")) network_graph(x, e = c("mention", "retweet", "reply", "quote"))
network_data(x, e = c("mention", "retweet", "reply", "quote")) network_graph(x, e = c("mention", "retweet", "reply", "quote"))
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 |
Retrieve data to know which users are connected to which users.
A from/to data edge data frame
An igraph object
network_graph()
rtweet-deprecated
Converts Twitter stream data (JSON file) into parsed data frame.
parse_stream(path, ...)
parse_stream(path, ...)
path |
Character, name of JSON file with data collected by
|
... |
Unused, keeping it for back compatibility. |
stream_tweets()
, rtweet-deprecated
## Not run: stream_tweets(timeout = 1, file_name = "stream.json", parse = FALSE) parse_stream("stream.json") ## End(Not run)
## Not run: stream_tweets(timeout = 1, file_name = "stream.json", parse = FALSE) parse_stream("stream.json") ## End(Not run)
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.
plain_tweets(x)
plain_tweets(x)
x |
The desired character vector or data frame/list with named column/element "text" to be cleaned and processed. |
Data reformatted with ascii encoding and normal ampersands and without URL links, line breaks, fancy spaces/tabs, fancy apostrophes,
Deletes a status of user's profile.
post_destroy(destroy_id, token = NULL)
post_destroy(destroy_id, token = NULL)
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 |
tweet_delete()
rtweet-deprecated
post_favorite( status_id, destroy = FALSE, include_entities = FALSE, token = NULL )
post_favorite( status_id, destroy = FALSE, include_entities = FALSE, token = NULL )
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 |
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
Other post:
post_follow()
,
post_friendship()
,
post_tweet()
post_follow( user, destroy = FALSE, mute = FALSE, notify = FALSE, retweets = TRUE, token = NULL ) post_unfollow_user(user, token = NULL) post_mute(user, token = NULL)
post_follow( user, destroy = FALSE, mute = FALSE, notify = FALSE, retweets = TRUE, token = NULL ) post_unfollow_user(user, token = NULL) post_mute(user, token = NULL)
user |
Character vector of screen names or user ids.
See |
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 |
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
Other post:
post_favorite()
,
post_friendship()
,
post_tweet()
Updates friendship notifications and retweet abilities.
post_friendship(user, device = FALSE, retweets = FALSE, token = NULL)
post_friendship(user, device = FALSE, retweets = FALSE, token = NULL)
user |
Character vector of screen names or user ids.
See |
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 |
Other post:
post_favorite()
,
post_follow()
,
post_tweet()
Create, add users, and destroy Twitter lists.
post_list( users = NULL, name = NULL, description = NULL, private = FALSE, destroy = FALSE, list_id = NULL, slug = NULL, token = NULL )
post_list( users = NULL, name = NULL, description = NULL, private = FALSE, destroy = FALSE, list_id = NULL, slug = NULL, token = NULL )
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 |
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 |
Response object from HTTP request.
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
Posts direct message from user's Twitter account
post_message(text, user, media = NULL, token = NULL)
post_message(text, user, media = NULL, token = NULL)
text |
Character, text of message. |
user |
Character vector of screen names or user ids.
See |
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 |
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 )
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 )
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 |
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 |
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
|
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 |
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
tweet_post()
, rtweet-deprecated
Other post:
post_favorite()
,
post_follow()
,
post_friendship()
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
.
rate_limit(resource_match = NULL, token = NULL) rate_limit_reset(endpoint, token = NULL) rate_limit_wait(endpoint, token = NULL)
rate_limit(resource_match = NULL, token = NULL) rate_limit_reset(endpoint, token = NULL) rate_limit_wait(endpoint, token = NULL)
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 |
endpoint |
Name of Twitter endpoint like |
https://developer.twitter.com/en/docs/twitter-api/v1/developer-utilities/rate-limit-status
Other tokens:
create_token()
,
get_token()
Reads Twitter data that was previously saved as a CSV file.
read_twitter_csv(file, unflatten = FALSE)
read_twitter_csv(file, unflatten = FALSE)
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. |
A tbl data frame of Twitter data
Other datafiles:
flatten()
,
write_as_csv()
Expose errors of the response
retrieve_errors(expr = NULL)
retrieve_errors(expr = NULL)
expr |
An expression that might cause an error.
If |
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() }
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
round_time(x, n, tz)
round_time(x, n, tz)
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) |
If POSIXct then POSIX. If date then Date.
## class posixct round_time(Sys.time(), "12 hours") ## class date unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))
## class posixct round_time(Sys.time(), "12 hours") ## class date unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))
Set up your client mechanism for the Twitter API.
rtweet_client(client_id, client_secret, app, scopes = NULL)
rtweet_client(client_id, client_secret, app, scopes = NULL)
client_id , client_secret
|
Application OAuth client ID and client Secret.
These are generally not required for |
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 |
scopes |
Default scopes allowed for users using this client.
Leave |
scopes
if (interactive()) { rtweet_client() }
if (interactive()) { rtweet_client() }
Authenticate methods to use the Twitter API.
See the instructions in vignette("auth", package = "rtweet")
.
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)
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)
client_id , client_secret
|
Application OAuth client ID and client Secret.
These are generally not required for |
api_key , api_secret
|
API key and secret. Deprecated in favor of |
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 |
scopes |
The permissions of the app, see |
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.
If the validation is successful the OAuth token.
For rtweet_app()
a rtweet_bearer
.
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.
https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code
Other authentication:
auth_as()
,
auth_get()
,
auth_save()
,
auth_setup_default()
## Not run: rtweet_app() ## End(Not run)
## Not run: rtweet_app() ## End(Not run)
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.
Provides the information about the rules
rules(x, ...)
rules(x, ...)
x |
An object returned by |
... |
Other arguments currently ignored. |
stream_add_rule()
and stream_rm_rule()
.
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.
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 )
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 )
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 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 You are not guaranteed to get exactly |
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 |
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 |
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 |
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 |
Note: The env_name
must match the ones you set up for the token you are using.
A tibble data frame of Twitter data.
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.
Note: Bolded operators ending with a colon should be immediately
followed by a word or quoted phrase (if appropriate)–e.g., lang:en
"" ~~ match exact phrase
# ~~ hashtag
@ ~~ at mentions)
url: ~~ found in URL
lang: ~~ language of tweet
from: ~~ authored by
to: ~~ sent to
retweets_of: ~~ retweet author
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
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
tweet_search_recent()
, tweet_search_all()
, rtweet-deprecated
Returns Twitter statuses matching a user provided search query.
search_tweets2 Passes all arguments to search_tweets. Returns data from one OR MORE search queries.
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(...)
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(...)
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 Some other useful query tips:
|
n |
Desired number of results to return. Results are downloaded
in pages when 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 You are not guaranteed to get exactly |
type |
Character string specifying which type of search
results to return from Twitter's REST API. The current default is
|
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., |
since_id |
Supply a vector of ids or a data frame of previous results to
find tweets newer than |
max_id |
Supply a vector of ids or a data frame of previous results to
find tweets older than |
parse |
If |
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 |
retryonratelimit |
If If you expect a query to take hours or days to perform, you should not
rely solely on |
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 |
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.
List object with tweets and users each returned as a data frame.
A tbl data frame with additional "query" column.
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets
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 Twitter users. The Twitter API limits the results to at most 1,000 users.
search_users(q, n = 100, parse = TRUE, token = NULL, verbose = TRUE)
search_users(q, n = 100, parse = TRUE, token = NULL, verbose = TRUE)
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 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 You are not guaranteed to get exactly |
parse |
If |
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 |
verbose |
Show progress bars and other messages indicating current progress? |
Data frame with one row for each matching user.
user_search()
, rtweet-deprecated
Other users:
as_screenname()
,
lists_subscribers()
,
lookup_users()
Choose which fields are used, by default all are returned. Usually all the first 3 are accepted together and the last two too.
set_fields( media = media_fields, poll = poll_fields, tweet = tweet_fields, place = place_fields, user = user_fields, list = list_fields )
set_fields( media = media_fields, poll = poll_fields, tweet = tweet_fields, place = place_fields, user = user_fields, list = list_fields )
media |
The fields you want from |
poll |
The fields you want from |
tweet |
The fields you want from |
place |
The fields you want from |
user |
The fields you want from |
list |
The fields you want from |
A list with the fields requested ready to be used in your requests to the API.
Fields
set_fields() set_fields(media = NULL) set_fields(place = NULL, user = NULL)
set_fields() set_fields(media = NULL) set_fields(place = NULL, user = NULL)
Permissions given to a token of a Twitter account. By default it allows everything.
set_scopes(read = TRUE, write = TRUE, tweet_moderate = TRUE, regenerate = TRUE)
set_scopes(read = TRUE, write = TRUE, tweet_moderate = TRUE, regenerate = TRUE)
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. |
A character with all the possible scopes or those allowed.
https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code
set_scopes()
set_scopes()
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).
A tibble with three variables and 24,000 observations
Open a streaming connection with Twitter and stores tweets for as long as you wish.
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 )
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 )
timeout |
time, in seconds, of the recording stream. |
file |
Path to a file where the raw streaming should be stored. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
append |
Append streaming to the file? Default does but it is recommended to have a new file for each call. |
parse |
If |
query |
If
|
dry |
Check if the addition or removal of the rule works. |
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.
The records in the streaming.
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.
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
# 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) }
# 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) }
Streams public statuses to a file via one of the following four methods:
Sampling a small random sample of all publicly available tweets
Filtering via a search-like query (up to 400 keywords)
Tracking via vector of user ids (up to 5000 user_ids)
Location via geo coordinates (1-360 degree location boxes)
Learn more in vignette("stream", package = "rtweet")
stream_tweets( q = "", timeout = 30, parse = TRUE, token = NULL, file_name = NULL, verbose = TRUE, append = TRUE, ... )
stream_tweets( q = "", timeout = 30, parse = TRUE, token = NULL, file_name = NULL, verbose = TRUE, append = TRUE, ... )
q |
Query used to select and customize streaming collection method. There are four possible methods:
|
timeout |
Integer specifying number of seconds to stream tweets for.
Stream indefinitely with The stream can be interrupted at any time, and |
parse |
Use |
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 |
file_name |
Character with name of file. If not specified,
will write to a temporary file |
verbose |
If |
append |
If |
... |
Other arguments passed in to query parameters. |
A tibble with one row per tweet
They were removed from the website.
The webpages describing how it used to work were removed.
filtered_stream()
, rtweet-deprecated
trends_available(token = NULL, parse = TRUE)
trends_available(token = NULL, parse = 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 |
parse |
If |
Data frame with WOEID column. WOEID is a Yahoo! Where On Earth ID.
Other trends:
get_trends()
Count tweets
tweet_counts_recent(query, ..., token = NULL, parse = TRUE, verbose = FALSE) tweet_counts_all(query, ..., token = NULL, parse = TRUE, verbose = FALSE)
tweet_counts_recent(query, ..., token = NULL, parse = TRUE, verbose = FALSE) tweet_counts_all(query, ..., token = NULL, parse = TRUE, verbose = FALSE)
query |
One query for matching Tweets. |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
The number of tweets for a given granularity
https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all
if (FALSE) { tcr <- tweet_counts_recent(query = "#rtweet", parse = FALSE) tca <- tweet_counts_all(query = "#rtweet", parse = FALSE) }
if (FALSE) { tcr <- tweet_counts_recent(query = "#rtweet", parse = FALSE) tca <- tweet_counts_all(query = "#rtweet", parse = FALSE) }
Will delete a tweet
tweet_delete(id, verbose = FALSE, token = NULL)
tweet_delete(id, verbose = FALSE, token = NULL)
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 |
tweet_post()
, tweet_search_recent()
, user_timeline()
Twitter API GET call to retieve the tweet in embedded form.
tweet_embed(screen_name, status_id, ...)
tweet_embed(screen_name, status_id, ...)
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. |
character
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' )
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' )
Look up tweets up to 100 at the same time.
tweet_get( id, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_get( id, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
At least a tweet id. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
This endpoint accepts a OAuth2.0 authentication (can be
created via |
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
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
if (FALSE){ tweet_get("567053242429734913", parse = FALSE) tweet_get(c("567053242429734913", "567053242429734913"), parse = FALSE) tweet_get(c("567053242429734913", "567053242429734913"), parse = TRUE) }
if (FALSE){ tweet_get("567053242429734913", parse = FALSE) tweet_get(c("567053242429734913", "567053242429734913"), parse = FALSE) tweet_get(c("567053242429734913", "567053242429734913"), parse = TRUE) }
Looks up who have liked a given tweet.
tweet_liking_users( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_liking_users( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A tweet id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { tlu <- tweet_liking_users("567053242429734913", n = Inf, verbose = TRUE) }
if (FALSE) { tlu <- tweet_liking_users("567053242429734913", n = Inf, verbose = TRUE) }
This function uses the API v2 to post tweets.
tweet_post(text, ..., token = NULL)
tweet_post(text, ..., token = NULL)
text |
Text of the tweet. |
... |
Other accepted arguments. |
token |
This endpoint accepts a OAuth2.0 authentication (can be
created via |
https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
if (FALSE) { # It requires the Oauth2.0 Authentication tp_id <- tweet_post("Posting from #rtweet with the basic plan") tweet_post() }
if (FALSE) { # It requires the Oauth2.0 Authentication tp_id <- tweet_post("Posting from #rtweet with the basic plan") tweet_post() }
Look up tweets quoting that tweet id.
tweet_quoted( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_quoted( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
At least a tweet id. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
This endpoint accepts a OAuth2.0 authentication (can be
created via |
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
if (FALSE){ tweet_quoted("1631945769748930561", parse = FALSE) }
if (FALSE){ tweet_quoted("1631945769748930561", parse = FALSE) }
Looks up who have retweeted a given tweet.
tweet_retweeted_by( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_retweeted_by( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A tweet id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
A data.frame with the user information of who retweeted it:
id, name, and username.
Other information depends on the expansions
and fields
requested.
if (FALSE) { rb <- tweet_retweeted_by("567053242429734913") }
if (FALSE) { rb <- tweet_retweeted_by("567053242429734913") }
Search in the Twitter archive
tweet_search_all( query, n = 500, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_search_all( query, n = 500, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
query |
One query for matching Tweets. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
OAuth2.0 requires tweet.read and users.read permissions.
https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all
if (FALSE) { sa <- tweet_search_all("#rtweet", parse = FALSE) }
if (FALSE) { sa <- tweet_search_all("#rtweet", parse = FALSE) }
Look up tweets from the last seven days that match a search query.
tweet_search_recent( query, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
tweet_search_recent( query, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
query |
One query for matching Tweets. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about the paginated queries (if any) and to store the data of each page. |
OAuth2.0 requires tweet.read and users.read permissions.
if (FALSE) { sr <- tweet_search_recent("#rtweet", sort_order = "relevancy", parse = FALSE) }
if (FALSE) { sr <- tweet_search_recent("#rtweet", sort_order = "relevancy", parse = FALSE) }
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.
tweet_shot(statusid_or_url, zoom = 3, scale = TRUE)
tweet_shot(statusid_or_url, zoom = 3, scale = TRUE)
statusid_or_url |
a valid Twitter status id (e.g. " |
zoom |
a positive number >= 1. See the help for |
scale |
auto-scale the image back to 1:1? Default it |
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.
magick
object
## 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)
## 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)
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.
tweet_threading(tw, traverse = c("backwards", "forwards"), verbose = FALSE)
tweet_threading(tw, traverse = c("backwards", "forwards"), verbose = FALSE)
tw |
|
traverse |
character, direction to traverse from origin status in |
verbose |
logical, output to console status of traverse. |
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()
).
Tweets in a structure like lookup_tweets()
.
rtweet-deprecated
, lookup_tweets()
For internal use only
tweets_with_users(x) users_with_tweets(x)
tweets_with_users(x) users_with_tweets(x)
x |
A list of responses, with one element for each page. |
A tweets/users tibble with users/tweets attribute.
user_block(...)
blocks or unblocks a target twitter user.
user_unblock(...)
is synonymous to user_block(..., unblock=TRUE)
.
user_block(user, unblock = FALSE, token = NULL) user_unblock(user, token = NULL)
user_block(user, unblock = FALSE, token = NULL) user_unblock(user, token = NULL)
user |
Character vector of screen names or user ids.
See |
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 |
List of users that are blocked.
user_blocked( id, n = 1000, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_blocked( id, n = 1000, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A user id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking
if (FALSE) { uf <- user_blocked("1599030512919650304", verbose = TRUE) }
if (FALSE) { uf <- user_blocked("1599030512919650304", verbose = TRUE) }
Collects the 800 most recent bookmarked tweets of a user.
user_bookmarks( id, n = 100, ..., expansions = NULL, fields = NULL, parse = TRUE, token = NULL, verbose = FALSE )
user_bookmarks( id, n = 100, ..., expansions = NULL, fields = NULL, parse = TRUE, token = NULL, verbose = FALSE )
id |
Twitter user id: character string identifying your account. |
n |
Number of tweets to retrieve. |
... |
Other arguments passed down to the API. |
expansions |
Set |
fields |
Set |
parse |
If |
token |
This endpoint only accept a OAuth2.0 authentication (can be
created via |
verbose |
A logical 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)
.
This endpoint requires a OAuth2.0 authentication, with tweet.read, users.read and bookmark.read permissions.
if (FALSE) { # Requires token_oa2 ub <- user_bookmarks(user_self()$id, parse = FALSE, n = Inf, token = token_oa2) }
if (FALSE) { # Requires token_oa2 ub <- user_bookmarks(user_self()$id, parse = FALSE, n = Inf, token = token_oa2) }
Looks up users by their username.
user_by_username( username, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_by_username( username, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
username |
A user name string or up to 100. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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
if (FALSE) { user_by_username("rOpenSci") user_by_username(c("Bioconductor", "R_Contributors")) }
if (FALSE) { user_by_username("rOpenSci") user_by_username(c("Bioconductor", "R_Contributors")) }
List of users that follow the specified user ID.
user_followers( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_followers( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A user id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers
if (FALSE) { uf <- user_followers("1599030512919650304", verbose = TRUE) }
if (FALSE) { uf <- user_followers("1599030512919650304", verbose = TRUE) }
List of users the specified user ID is following.
user_following( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_following( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A user id string. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following
if (FALSE) { uf <- user_following("1599030512919650304", verbose = TRUE) }
if (FALSE) { uf <- user_following("1599030512919650304", verbose = TRUE) }
Looks up tweets liked by a user.
user_liked_tweets( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_liked_tweets( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A tweet id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { ult <- user_liked_tweets("1599030512919650304", verbose = TRUE) }
if (FALSE) { ult <- user_liked_tweets("1599030512919650304", verbose = TRUE) }
Looks up lists a user follows.
user_list_follows( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_list_follows( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { ulf <- user_list_follows("1051050384") }
if (FALSE) { ulf <- user_list_follows("1051050384") }
Looks up users by their username.
user_lists( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_lists( ids, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A user name string or up to 100. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { ul <- user_lists("1051050384") }
if (FALSE) { ul <- user_lists("1051050384") }
Looks up to 800 tweets mentioning a user.
user_mentions( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_mentions( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A user id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { um <- user_mentions("1599030512919650304", verbose = TRUE) }
if (FALSE) { um <- user_mentions("1599030512919650304", verbose = TRUE) }
Looks up the muted users.
user_muted( ids, n = 1000, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_muted( ids, n = 1000, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A list id. |
n |
Number of users to query. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
.
https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting
if (FALSE) { um <- user_muted(user_self()$id) }
if (FALSE) { um <- user_muted(user_self()$id) }
Looks up users.
user_search( ids, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_search( ids, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
ids |
A user id string or up to 100. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
A data.frame with the id, name and username of the accounts.
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)
.
https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users
if (FALSE) { us <- user_search(c("1599030512919650304", "2244994945"), verbose = TRUE) }
if (FALSE) { us <- user_search(c("1599030512919650304", "2244994945"), verbose = TRUE) }
Looks up tweets posted by a user.
user_self( expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_self( expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
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)
https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me
if (FALSE) { me <- user_self() }
if (FALSE) { me <- user_self() }
Looks up the timeline of a user with up to 800 tweets in the last 7 days.
user_timeline( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_timeline( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A tweet id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
if (FALSE) { ut <- user_timeline("1599030512919650304", verbose = TRUE) }
if (FALSE) { ut <- user_timeline("1599030512919650304", verbose = TRUE) }
Looks up tweets posted by a user.
user_tweets( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
user_tweets( id, n = 100, expansions = NULL, fields = NULL, ..., token = NULL, parse = TRUE, verbose = FALSE )
id |
A user id string. |
n |
Number of tweets to query. |
expansions |
Set |
fields |
Set |
... |
Other arguments passed to the API. |
token |
These endpoints only accept a bearer token (can be created via
|
parse |
If |
verbose |
A logical value to provide more information about paginated queries. |
https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets
if (FALSE) { ut <- user_tweets("1599030512919650304", verbose = TRUE) }
if (FALSE) { ut <- user_tweets("1599030512919650304", verbose = TRUE) }
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.
users_data(tweets) tweets_data(users)
users_data(tweets) tweets_data(users)
tweets |
A data frame of tweets. |
users |
A data frame of users. |
user_data()
returns a data frame of users; tweets_data()
returns a data frame of tweets.
Saves as flattened CSV file of Twitter data.
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")
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")
x |
Data frame returned by an rtweet function. |
file_name |
Desired name to save file as. If |
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". |
Saved CSV files in current working directory.
Other datafiles:
flatten()
,
read_twitter_csv()
Other datafiles:
flatten()
,
read_twitter_csv()