A
A
Alex Ponomarev2020-02-22 15:59:02
API
Alex Ponomarev, 2020-02-22 15:59:02

API data filter How to do?

learned how to get data (list of group members) using the groups.getMembers method
But I can’t figure out how to filter them by gender, city and age

$limit = 1000;
$users = array();
do {
  $offset = $page * $limit;
  //Получаем список пользователей

  $members = json_decode(file_get_contents("https://api.vk.com/method/groups.getMembers?group_id=37372389&v=5.16&offset=$offset&count=$limit&fields=sex,bdate&access_token=$token"),true);
 
  foreach ($members['response']['users'] as $user_array) {
    // Если пользователь указал дату рождения и пользователь - мужчина...
    if ((isset($user_array['bdate'])) && ($user_array['sex'] == 2)) {
        // ... и если в дате рождения три компонента (ДД.ММ.ГГГГ)...
        if (count(explode(".", $user_array['bdate'])) == 3) {
            // то вычисляем возраст (формулу нашел в интернете)
            $age = floor((time()-strtotime($user_array['bdate']))/(60*60*24*365.25));
            // Если возраст нам подходит, выводим id пользователя с переводом строки
            if ($age > 25) {
                echo $user_array['uid'] . "<br/>";
            }
        }
    }
}

The code does not run, tell me where the error is please. and if there is something to read about how to create filters for such data, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AUser0, 2020-02-22
@AUser0

The do { block does not have a closing curly brace and a corresponding continuation.
The $page and $token variables used in the URL are not defined.
The VK service quite predictably swears at the lack of user authorization, the list does not give back.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question