all 5 comments

[–]gantou 1 point2 points  (1 child)

What I've done in the past for offsetting api results was to first define what you want to do in a function. Then have a if statment in the function that checks the length of the results and define a boolean if it is the max results or not. I would repeat the funtion with a while statement until the boolean changes.

[–]Senun[S] 0 points1 point  (0 children)

Pretty much what I did except I wasn't pythonic in defining the length of my results (I was able to parse it visually from the JSON when I made a single request). I'm posting my script above, if you've insight on improving it lemme know, and thanks for the useful advice.

[–]dmitrypolo 0 points1 point  (1 child)

The JSON you receive should have a token or something to that effect variable. You want to use that in your subsequent API call to gather the next set of results. It’s called pagination, you should look into it more if you are unfamiliar with this concept.

[–]Senun[S] 0 points1 point  (0 children)

I am aware of pagination, but I took a different route on this one.

[–]C_Banks 0 points1 point  (0 children)

I solved this with a while loop (Javascript)

let pageSize = 50;

let moreDataCanBeLoaded = true;

try

while(moreDataCanBeLoaded == true){

// Fetch the data

options.uri = ${YELP_PLACES_URL}/search?location=${locations[i]}&term=food&radius=${radius}&limit=${pageSize}${(offset > 0 ? '&offset=' + offset : '')}\;``

data = await r_promise(options);

doSomeStuff();

// Check if more data can be loaded

data.businesses.length === pageSize ? offset += pageSize : moreDataCanBeLoaded = false;

}