get_all_tweets: Get tweets from full archive search

View source: R/get_all_tweets.R

get_all_tweetsR Documentation

Get tweets from full archive search

Description

This function collects tweets by query string or strings between specified date ranges.

Usage

get_all_tweets(
  query = NULL,
  start_tweets,
  end_tweets,
  bearer_token = get_bearer(),
  n = 100,
  file = NULL,
  data_path = NULL,
  export_query = TRUE,
  bind_tweets = TRUE,
  page_n = 500,
  context_annotations = FALSE,
  verbose = TRUE,
  ...
)

Arguments

query

string or character vector, search query or queries

start_tweets

string, starting date; default to now - 30 days

end_tweets

string, ending date; default to now - 30 seconds

bearer_token

string, bearer token

n

integer, upper limit of tweets to be fetched

file

string, name of the resulting RDS file

data_path

string, if supplied, fetched data can be saved to the designated path as jsons

export_query

If TRUE, queries are exported to data_path

bind_tweets

If TRUE, tweets captured are bound into a data.frame for assignment

page_n

integer, amount of tweets to be returned by per page

context_annotations

If TRUE, context_annotations will be fetched. Note it will limit the page_n to 100 due restrictions of Twitter API.

verbose

If FALSE, query progress messages are suppressed

...

arguments will be passed to build_query() function. See ?build_query() for further information.

Details

The function can also collect tweets by users. These may be specified alongside a query string or without. When no query string is supplied, the function collects all tweets by that user.

If a filename is supplied, the function will save the result as a RDS file.

If a data path is supplied, the function will also return tweet-level data in a data/ path as a series of JSONs beginning "data_"; while user-level data will be returned as a series of JSONs beginning "users_".

Value

When bind_tweets is TRUE (default), the function returns a data frame. Nothing otherwise.

Examples

## Not run: 
bearer_token <- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

get_all_tweets(query = "BLM", 
               start_tweets = "2020-01-01T00:00:00Z", 
               end_tweets = "2020-01-05T00:00:00Z", 
               bearer_token = get_bearer(), 
               data_path = "data",
               n = 500)
  
get_all_tweets(users = c("cbarrie", "jack"),
               start_tweets = "2021-01-01T00:00:00Z", 
               end_tweets = "2021-06-01T00:00:00Z",
               bearer_token = get_bearer(), 
               n = 1000)
                            
get_all_tweets(start_tweets = "2021-01-01T00:00:00Z", 
               end_tweets = "2021-06-01T00:00:00Z",
               bearer_token = get_bearer(), 
               n = 1500, 
               conversation_id = "1392887366507970561")

## End(Not run)

cjbarrie/academictwitteR documentation built on Dec. 20, 2024, 6:03 p.m.