Skip to content

Instantly share code, notes, and snippets.

@trianglesis
Created July 27, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trianglesis/fe00dab42099f1f75a21c87dc4ef9d8b to your computer and use it in GitHub Desktop.
Save trianglesis/fe00dab42099f1f75a21c87dc4ef9d8b to your computer and use it in GitHub Desktop.
This script allows you to get all comments from post id array string.
var comment;
var comment_id;
var comment_from_id;
var comment_date;
var comment_likes;
var comments_format;
var comments_list = [];
var myList = Args.post_id_array_str;
var listSeparator = ",";
var listItemsType = "integer";
var result = [];
var charsLength = myList.length;
var currentPosition = 0;
var previousSeparatorPosition = -1;
var item;
while (currentPosition < charsLength) {
if (myList.substr(currentPosition, 1) == listSeparator) {
item = myList.substr(previousSeparatorPosition + 1, currentPosition - previousSeparatorPosition - 1);
if (listItemsType == "integer") {
item = parseInt(item);
}
result.push(item);
previousSeparatorPosition = currentPosition;
}
currentPosition = currentPosition + 1;
}
var post_id;
var posts = result;
while (posts.length != 0){post_id = posts.shift();
var owner_id = Args.owner_id;
var comments = API.wall.getComments(
{"owner_id":(owner_id),
"post_id":(post_id),
"need_likes":"1",
"offset":"0",
"count":"100",
"sort":"asc",
"preview_length":"1",
"extended":"0",
"v":"5.27"});
comment = comments.items;
comment_id = comment@.id;
comment_from_id = comment@.from_id;
comment_date = comment@.date;
comment_likes = comment@.likes;
comment_likes = comment_likes@.count;
comments_format = [(comment_id),(comment_from_id),(comment_date),(comment_likes)];
comments_list.push(comments_format);
var comments_cnt = comments.count;
var offset_comments = 100;
while (offset_comments < comments_cnt)
{comments = comments + API.wall.getComments(
{"owner_id":(Args.owner_id),
"post_id":(post_id),
"need_likes":"1",
"offset":(offset_comments),
"count":"100",
"sort":"asc",
"preview_length":"1",
"extended":"0",
"v":"5.27"});
comment = comments.items;
comment_id = comment@.id;
comment_from_id = comment@.from_id;
comment_date = comment@.date;
comment_likes = comment@.likes;
comment_likes = comment_likes@.count;
comments_format = [(comment_id),(comment_from_id),(comment_date),(comment_likes)];
comments_list.push(comments_format);
offset_comments = offset_comments + 100;};
};
return comments_list;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment