Hello. Both of the following codes return comments on the same post from the wall. The difference is that the first one returns 100 comments to the post once, and the second to 2500. The question is to transfer this 25-fold iteration to the first code, since with the first code you can also extract individual user’s comments on his ID and in addition - refer to the post without specifying its ID - by number, whereas the second code in the arguments requires an exact ID of the post.
CODE number 1:
var owner_id = Args.owner_id; var user_id = Args.user_id; var offset = Args.offset; var post_count = Args.post_count; if (post_count == null) post_count = 1; // НА ОБРАБОТКЕ 1 ПОСТ // Получаем список постов var posts = API.wall.get({ "owner_id": owner_id, "offset": offset, "count" : 100, }); var i = 0; var userComments = {}; while(i < posts.items.length && i < post_count) { var post_id = posts.items[i].id; var comments = API.wall.getComments({ "owner_id": owner_id, "post_id": post_id, "offset": 0, "count" : 100, // максимально возможное количество коментов, // кот. можно получить с одного вызова }); var j = 0; while(j < comments.items.length) { if (user_id == null || comments.items[j].from_id == user_id) userComments.push(comments.items[j]); j = j + 1; } i = i + 1; } return userComments; CODE number 2:
var owner_id = Args.owner_id; var post_id = Args.post_id; var offset = Args.offset; var count = Args.count; if(post_id == null || owner_id == null){ return {"count": 0, "items": []}; // Если параметры не заданы, возвращаем пустой массив } if(count == null){ count = 10; // Значение по умолчанию } if(offset == null){ offset = 0; // Значение по умолчанию } var i = 0; var items = []; while(i < 25 && count > items.length){ var cur_count = count - items.length; if(cur_count > 100){ cur_count = 100; } items = items + API.wall.getComments({"owner_id": owner_id, "post_id": post_id, "offset": offset+100*i, "count": cur_count, "need_likes":1})["items"]; i = i + 1; } return {"count": items.length, "items": items};