0

I'm working with the Discogs API and am running into an issue with rate limiting. I have a loop to to cycle through all of my release id's and then pull back further release information. The rate limit is 25 calls every 60 seconds, but I can't seem to find a way to limit the call from within httr. I'm wondering if perhaps a for loop would be more ideal?

I have pasted my code below:

releasedata <- lapply(as.list(collection$release_id), function(obj){
  url <- httr::GET(paste0("https://api.discogs.com/releases/", obj))
  url <- rjson::fromJSON(rawToChar(url$content))
  data.frame(release_id = obj, 
             label = url$label[[1]]$name %||% NA,
             year = url$year %||% NA, 
             title = url$title %||% NA, 
             artist_name = url$artist[[1]]$name %||% NA, 
             styles = url$styles[[1]] %||% NA,
             genre = url$genre[[1]] %||% NA,
             average_note = url$community$rating$average %||% NA, 
             votes = url$community$rating$count %||% NA, 
             want = url$community$want %||% NA, 
             have = url$community$have %||% NA, 
             lowest_price = url$lowest_price %||% NA, 
             country = url$country %||% NA)
}) %>% do.call(rbind, .) %>% 
  unique()

If anybody can recommend an appropriate loop for this, I'd appreciate the help.

Ed Cunningham
  • 179
  • 1
  • 3
  • 17
  • 2
    Try `Sys.sleep(2.5)`. A little conservative but makes sure you don't make too many calls within 60 secs – OganM Aug 17 '18 at 23:48
  • I have thought about sys.sleep, however, how would this fit into the code pasted above? – Ed Cunningham Aug 18 '18 at 07:11
  • put it anywhere in the loop. just makes sure the loop overall takes longer than 2.5 seconds so you won't be making too many calls – OganM Aug 19 '18 at 22:59
  • I've put Sys.sleep in multiple locations of my loop, but it prevents my loop from running. WhY? – Ben Sep 11 '21 at 14:57

0 Answers0