C
C
CrazyKing2018-02-01 11:25:41
PHP
CrazyKing, 2018-02-01 11:25:41

How to get more than 5000 friends using the friends.get() method using the VKontakte API?

I'm trying to get a list of friends from a user using PHP, the number of friends is more than 9 thousand, in the VK API the "friends.get" method has restrictions on getting only 5000.
Initially I tried to get it this way:

$token = "XXXXXX"; //токен
$friends_get = api ('https://api.vk.com/method/friends.get?order=name&fields=name&name_case=ins&v=5.28&access_token='.$token);
$count = $friends_get['count']; // получаем массив пользователей
for ($i=0; $i < $count; $i++) { 
$banned = $friends_get ['items'][$i]['deactivated'];//Выбираем пользователей со статусом 'deactivated'
$id = $friends_get ['items'][$i]['id']; //получаем список ID пользователей
if ($banned == banned){ //проверяем, если страница заблокирована

Then I drove the whole thing into an array and sorted it out in a loop to select only the blocked ones, that’s not the point ..
The problem arose in the fact that there are more than 5 thousand friends and I can’t figure out how to pick up the rest.
Tried a query like this:
$members = json_decode(file_get_contents("https://api.vk.com/method/friends.get?user_id=436764&offset=9000&fields=name"),true);

I added "offset =" and it seems that I managed to take out another part, but I can't figure out how to combine them with the previous five thousand, or how to run this query several times and put everything together.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-02-01
@sergiks

Do it in a loop. Each time increase the offset by 5000 until it is greater than the counttotal number of friends returned in the field. Don't forget about the limit of 3 requests per second.
You can still get confused and push all the code into execute() , then a single request will follow from PHP, and the cycle will scroll to the sides of the VK.

V
Vitaly, 2018-02-01
@vshvydky

take the vk-io module there has its own api over vk, it allows you to collect data streams in a couple of lines

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question