Answer the question
In order to leave comments, you need to log in
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){ //проверяем, если страница заблокирована
$members = json_decode(file_get_contents("https://api.vk.com/method/friends.get?user_id=436764&offset=9000&fields=name"),true);
Answer the question
In order to leave comments, you need to log in
Do it in a loop. Each time increase the offset by 5000 until it is greater than the count
total 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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question