I am still trying to figure out how to handle YouTube api pageToken

Wappler Team I need some help in understanding what is the best way to return more than the default 50 items the YouTube api gives using the pageToken parameter from the YouTube api documentation. So far a few members of the Wappler community has tried to help me on this given a few times that I have reach out here in the community, but from our observation it seems the “While” in Core Actions cannot handle or refused to loop through the YouTube api using the pageToken=nextPageToken that we have set to global and use as one of the “While” condition.

Here is a simple image showing the setup of what should cause the “While” to loop through the api call to get more than 50 items but it seems its not working.

Hi,
I’ve had a look through this as I need to use the YouTube API shortly.

I think it works fine within the while loop, but may not give the results you’re expecting to see… the API will only ever return the final set of results in the browser (so if your maxResults is 50 you will only ever see the final 50 results).

Though the query does retrieve more results, you’ll need to repeat them and save them somewhere to access the previous results sets.

To use the pagination practically you need to either:

Repeat the results and save each call somewhere to access all the looped values.

For example this calls the API twice and retrieves 10 records each time

image

the action inserts 20 records to the db (which could then be queried and returned):
image

but only the final 10 results show in the browser from the API.

or

add buttons to your page which call the API again and use the nextpagetoken or prevpagetoken so the user can cycle through the results. So you display x number of results in the page at any one time, add a GET variable to the API call to process the tokens.

Hope that helps a bit, if not if you can share a little more of your use case?

Thanks for this info.

Now this begs the question, does Wappler have a way to save the result of an API in an array server side much like they do here for client side? ( Wappler Documentation - Working with Arrays)

From this thread …

So, my best bet is to save the responses in a database then and forget about trying to use an array?

These could both be good options to achieve an output as an object/array if you’re using Node JS. The top one has been assigned to @patrick so the functionality may be coming along in Wappler some time soon? This is a good use case, but I’m sure there are others.

This would probably be faster than writing to the DB in your server action, I guess it depends if there’s any value in having the results saved more permanently?

If on PHP you could use a custom formatter too using:

https://www.php.net/manual/en/function.array-push.php

or similar.

Thanks for this info. Well, I cannot wait to see what Wappler come up for getting objects in an array server side.