rtweet icon indicating copy to clipboard operation
rtweet copied to clipboard

search_tweets not retrieving tweets with status ID less than or equal to max_id

Open tarekmkassab opened this issue 5 years ago • 1 comments

Problem

I'm passing a specific status ID to max_id in the search_tweets function, but I keep retrieving tweets with larger status ID, including subsequent retrievals.

Expected behavior

Retrieve tweets with an ID less than (that is, older than) or equal to max_id, as mentioned in the documentation. For the example below, I'm passing x1440047230140837891 to max_id , whose corresponding tweet was created in 9/20/2021, but all of the retrieved tweets are from 9/21/2021, and subsequent tweet retrievals are often not older than the previous ones.

Reproduce the problem

# package to collect tweets from the Twitter API
library(rtweet) 

# to differentiate file names
i <- 1
oldest_status_id = "x1440047230140837891"

# automating the process
repeat {

# constructing the file name
filename_csv <- paste("Rtweet Canadian Election", i, sep = " ")

# search tweets
canada_elections <- search_tweets(q = "#elxn44", n = 18000, type = "recent", max_id = oldest_status_id, include_rts = TRUE, token = user_token)

# save to csv file
write_as_csv(canada_elections, filename_csv, prepend_ids = TRUE, na = "", fileEncoding = "UTF-8")

# get csv file name
previous_filename <- paste(filename_csv, ".csv", sep = "")

# read data of previously written csv file
previous_file <- read.csv(previous_filename)

# get the oldest status id 
oldest_status_id <- min(previous_file$status_id, na.rm=T)

# increment file name
i <- i + 1

# sleep for 15 minutes 
Sys.sleep(900)
}

rtweet version

0.7.0

Session info

loaded via a namespace (and not attached):
 [1] prettyunits_1.1.1 fansi_0.5.0       crayon_1.4.1      utf8_1.2.2        R6_2.5.1          lifecycle_1.0.0  
 [7] jsonlite_1.7.2    magrittr_2.0.1    pillar_1.6.2      httr_1.4.2        progress_1.2.2    rlang_0.4.11     
[13] curl_4.3.2        vctrs_0.3.8       ellipsis_0.3.2    tools_4.1.1       hms_1.1.0         compiler_4.1.1   
[19] pkgconfig_2.0.3   askpass_1.1       openssl_1.4.5     tibble_3.1.4     

tarekmkassab avatar Sep 21 '21 21:09 tarekmkassab

Upon further reading of this bug, I think this was already fixed on the devel version. Thanks for adding the session Info. If you test the current devel version and find it is not, let me know.

llrs avatar Nov 20 '21 08:11 llrs