Home computickets Getting Wall posts in VK via Execute

Getting Wall posts in VK via Execute

Author

Date

Category

Trying to get all the posts from the wall in VK. I use the Execute method. Method code:

var iTers = 25;
var count = 100;
var posts = [];
var req_params = {
    "Owner_ID": args.id,
    "Offset": 0,
    "Count": Count,
    "V": "5.34"
};
var i = 0;
While (I & LT; ITERS) {
  REQ_PARAMS.OFFSET = I * Count + ITERS * Count * Args.offset;
  Var Response = API.Wall.get (REQ_PARAMS);
  Var Items = response.Items;
  if (Items.Length == 0) {
    RETURN POSTS;
  }
  Posts.push (Items);
  i = i + 1;
}
RETURN POSTS;

Faced such a problem: This code returns a list in JSON with posts, each of which contains the text field. Upon receipt, for example, more than 30,000 posts from one page, the total volume of all responses is ~ 50MB (this is a lot). To solve the problem, I decided to change the code of the method, by adding to the resulting array not the entire object of the post, but only those of its fields that I need. Example:

... // Nothing changed
While (I & LT; ITERS) {
  ... // here too
  var j = 0;
  While (J & LT; Items.Length) {
    var tmp_item = {};
    tmp_item.id = items [j] .id;
    tmp_item.date = items [j] .date;
    tmp_item.likes = items [j] .likees.count;
    TMP_ITEM.Reposts = Items [j] .reposts.count;
    Posts.push (TMP_Item);
    j = j + 1;
  }
  // Posts.push (Items);
  i = i + 1;
}
RETURN POSTS;

But this code does not fit into the limit by the number of operations per request. If you change VAR COUNT with 100 to 6 , the number of operations becomes valid and total size of all answers ~ 2MB, but this code works twice longer.

The question is as follows: Is it possible to get all the posts from the wall without the text field for more or less normal time?

UPD (a year later). This thing works and quite well: vk-top .


Answer 1, Authority 100%

Maybe it was possible to do and better, but so far only invented this:

var iTers = 25;
var count = 100;
var posts = [];
var req_params = {
    "Owner_ID": args.id,
    "Offset": 0,
    "Count": Count,
    "V": "5.34"
};
var i = 0;
While (I & LT; ITERS) {
  REQ_PARAMS.OFFSET = I * Count + ITERS * Count * Args.offset;
  Var Items = API.Wall.get (Req_params) .Items;
  if (Items.Length == 0) {
    RETURN POSTS;
  }
  VAR IDS = Items @ .id;
  VAR TMP = {};
  TMP.Chunk_size = ids.Length;
  TMP.IDS = IDS;
  tmp.likes = items @ .likes @ .count;
  TMP.Reposts = Items @ .reposts @ .count;
  TMP.DATES = Items @date;
  Posts.push (TMP);
  i = i + 1;
}
RETURN POSTS;

An example of an answer:

response: [{
  Chunk_size: 3,
  IDS: [678032, 685909, 685908],
  Likes: [1143, 154, 215],
  Reposts: [95, 6, 11],
  Dates: [1434489988, 1451844879, 1451840889]
}, {
  Chunk_size: 3,
  IDS: [685907, 685905, 685904],
  Likes: [760, 493, 111],
  Reposts: [48, 63, 1],
  Dates: [1451833975, 1451831406, 1451827220]
}, {
  Chunk_size: 3,
  IDS: [685903, 685901, 685899],
  Likes: [197, 486, 851],
  Reposts: [11, 24, 56],
  Dates: [1451823624, 1451818995, 1451815289]
}]

The receipt time has decreased by about 20%, the final size of all the answers has decreased by an average of 90%.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions