F
F
fierfoxik2017-05-03 16:21:23
JavaScript
fierfoxik, 2017-05-03 16:21:23

How to update offset in vk api?

There is a function loadPhoto which takes user id, album id and offset. If offset is not passed, then by default it is 0. In it, we call the vk api method with settings, upload 150 photos each.
In the click handler, we only pass ids to loadPhoto.
In the handler on the scroll with the trigger, we call loadPhoto and it is already necessary to specify the offset there to load new photos.
drawPhoto is just a draw function.
The problem is this: how to update offset to upload new photos and as soon as all the photos that are in the album are uploaded, stop uploading.
So far, we have reached the point that we check the received data from VK and if their length is all the time = 150, then += 150 will fall into the offset argument, then we take an empty variable and assign offset to it and pass it to the argument in the scroll handler. Works so-so, uploaded more photos than there are in the album.

function loadPhoto(profileID, albumID, offset) {
  albumName = albumID;
  if (typeof offset == 'undefined') {
    offset = 0;
  }

  VK.api('photos.get', {
    v: 5.62,
    owner_id: profileID,
    album_id: albumID,
    offset: offset,
    rev: 1,
    photo_sizes: 1,
    count: 150
  }, function startLoadPhoto(result) {
    drawPhoto(result.response.items);
    if (result.response.items.length == 150) {
      offset += 150;
      setOffset = offset;
    }
  });

};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question