Not sure if I’m doing something wrong or if this is a bug. I’m trying to get all photos from a Google album. Google serves a max of 100 photos at a time and provide a nextPage token to iterate through. I’m trying to use While to loop through while a nextpagetoken is provided.
What’s happening is the page loops through but only shows the last api_copy. I’ve confirmed this by changing the number of records returned by the API in each request using the pageSize parameter. The number of images returned in the api_copy is different. Those are also the last images in the album.
Hi.
The while loop’s output is not the same as a repeat step. You will always just get the last iteration’s value outside the loop.
For the steps/data in the loop, you will have to do the processing inside the while loop itself.
That’s weird. I would have thought it would work the same way as a PHP or Javascript while. What’s the purpose of the while then and why is it different in Wappler?
No, the purpose of while is exactly the same as in any other language. Its just different in terms of how output works as compared to a repeat step in Wappler.
This will output a list of all the values until the while condition is met. It isn’t dependent on knowing the number of loops. (Perhaps I’ve misunderstood the issue.)
I have used a while loop in the past and written a custom formatter that combines the arrays that are received from a query/api call. I’ll see if I can find it
(note: each of the set values has a local and global name. It is the global one I will use)
I end up with one set of results (all pages of retrieved data) in an output value called items
Mine is not a Google call so you will need to adjust the pagination reference to the nextPageToken etc. but the sructure should get you closer to what you want
Eventually we should make some kind of array store component also for server connect that you can use to init, add, append and output data in various steps. Maybe @patrick can check this.
Thanks for this. Can’t seem to get it to work yet and Google just pinged me for going over my limit for the day so I’ll get back to it tomorrow. Just wanted to let you know I appreciate the help.
Make sure for the Set Value steps you have a ‘Global Name’ set (I always make mine different to the local ‘Name’ property, just to be sure). Also make sure that when you use it later, you use the global name too. It won’t show in the picker so you have to type it by hand.
If you want to share your new API steps with me so I can have a look, please do.