A
A
Alex Ponomarev2020-02-22 10:24:00
In contact with
Alex Ponomarev, 2020-02-22 10:24:00

Vk api can't find error?

$token = $_SESSION['logged_id1'];
$page = 0;
$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 should get a list of group subscribers and filter them by gender and age. tell me where is the error.

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