I use this method of receiving goods, but because it allows you to receive only 200 products at a time, you have to use the same code again, only manually prescribe an offset (offset) of 200, etc., it takes a huge amount of time with a large group. How can I optimize the code so that all the products can be parsed without my participation in the offset?

$h = file_get_contents("https://api.vk.com/method/market.get?owner_id=-$group&offset=$offset&count=200&access_token=$token&v=5.59"); $tov = $array['response']['count']; //получаю общее кол-во товаров. $array = json_decode($h,true); 

    1 answer 1

    You can use the execute method to execute up to 25 queries simultaneously. That is, you can receive up to 5,000 products at a time. If you need more - enter this method in the loop.

    Here is a sample code for execute to output up to 2,400 entries from the community wall:

     var owner_id = Args.owner_id; var posts_num = parseInt(Args.count); var offset = parseInt(Args.offset); //если меньше 100 - 1 запрос и на выход if (posts_num <= 100) { return API.wall.get({"owner_id": owner_id, "count": posts_num, "offset": offset}).items; } //если больше 2500 - ничего не выйдет, переопределяем переменную на 2500 if (posts_num > 2500) { posts_num = 2500; } var out = {}; while (out.length < posts_num) { var count = 100; if (posts_num < 100) { count = posts_num; } out = out + API.wall.get({"owner_id": owner_id, "count": count, "offset": offset}).items; offset = offset + count; }; return out; 
    • But this will not work if the program has produced 4,000 products, but only 4001 - Racan
    • @ Racan, so what’s the problem with putting the request with the execute into a loop, if the number of items is more than what can be sparsed? - Felix