Created
March 28, 2022 03:50
-
-
Save johnbaums/6ea4f71244b81e4d12d9c8611fe1dbf3 to your computer and use it in GitHub Desktop.
Download zotero collection, with pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(jsonlite) | |
# create an empty list to store results | |
items <- list() | |
i <- 1 # initialise counter to 1. This is used to specify the start index for queries | |
# We can download at most 100 records at a time, so we download in pages, | |
# increasing the start index by 100 each time. We do this until the result of | |
# the query has fewer than 100 results (i.e. we've retrieved the last page of | |
# results). | |
while(length(items) == 0 || nrow(items[[length(items)]]$data) == 100) { | |
message(i) | |
items <- c(items, list(fromJSON(sprintf('https://api.zotero.org/groups/1595276/collections/H6NCM36Y/items/top?start=%s&limit=100', i)))) | |
i <- i + 100 | |
} | |
# Pull out columns of interest and combine the pages | |
bib <- lapply(items, function(x) { | |
select(as_tibble(x$data), key, title, creators, abstractNote, date, url) | |
}) %>% | |
bind_rows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment