View source: R/setup-functions.R
pull_tweet_data | R Documentation |
With a TAGS archive imported into R, pull_tweet_data()
uses the
rtweet package to query the Twitter API. Using rtweet requires Twitter
API keys associated with an approved developer account. Fortunately, the
rtweet vignette,
Authentication,
provides a thorough guide to obtaining Twitter API keys and authenticating
access to the Twitter API. Following the directions for "Apps," you will
run the rtweet::rtweet_app()
function.
pull_tweet_data(df = NULL, url_vector = NULL, id_vector = NULL, n = NULL)
df |
A dataframe of containing the column name 'status_url'
(i.e., the hyperlink to specific statuses), such as that returned by
|
url_vector |
A vector of status URLs, such as as those contained in
the 'status_url' column of a dataframe returned by
|
id_vector |
A vector of statuses (i.e., ID numbers, such as
those contained in the 'id_str' column of a dataframe returned by
|
n |
The number of statuses to look up, by default the total number of tweet ID numbers available, but capped at 90,000 due to Twitter API limitations. |
This function requires authentication; please see
vignette("setup", package = "tidytags")
A dataframe of statuses and full metadata from the Twitter API
Read more about rtweet authentication setup at
vignette("auth", package = "rtweet")
## Import data from a TAGS tracker:
example_tags_tracker <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8"
tags_content <- read_tags(example_tags_tracker)
if (rtweet::auth_has_default()) {
## Use any of three input parameters (TAGS dataframe, `status_url`
## column, or `id_str` column)
tweets_data_from_df <- pull_tweet_data(tags_content)
tweets_data_from_url <-
pull_tweet_data(url_vector = tags_content$status_url)
tweets_data_from_ids <- pull_tweet_data(id_vector = tags_content$id_str)
## Specifying the parameter `n` clarifies how many statuses to look up,
## but the returned values may be less than `n` because some statuses
## may have been deleted or made protected since the TAGS tracker
## originally recorded them.
tweets_data_10 <- pull_tweet_data(tags_content, n = 10)
## Note that the following two examples will return the same thing:
one_tweet_data <-
pull_tweet_data(url_vector =
"https://twitter.com/tweet__example/status/1176592704647716864")
one_tweet_data <- pull_tweet_data(id_vector = "1176592704647716864")
one_tweet_data
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.