Skip to contents

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.

Usage

pull_tweet_data(df = NULL, url_vector = NULL, id_vector = NULL, n = NULL)

Arguments

df

A dataframe of containing the column name 'status_url' (i.e., the hyperlink to specific statuses), such as that returned by read_tags()

url_vector

A vector of status URLs, such as as those contained in the 'status_url' column of a dataframe returned by tidytags::read_tags()

id_vector

A vector of statuses (i.e., ID numbers, such as those contained in the 'id_str' column of a dataframe returned by tidytags::read_tags()

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.

Value

A dataframe of statuses and full metadata from the Twitter API

Details

This function requires authentication; please see vignette("setup", package = "tidytags")

See also

Read more about rtweet authentication setup at vignette("auth", package = "rtweet")

Examples


# \donttest{
## Import data from a TAGS tracker:
example_tags_tracker <- "18clYlQeJOc6W5QRuSlJ6_v3snqKJImFhU42bRkM_OX8"
tags_content <- read_tags(example_tags_tracker)
#>  Reading from "#aect19 tweet collector".
#>  Range ''Archive''.

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
}
# }