H
H
Helen-Elena2018-07-12 00:25:16
PHP
Helen-Elena, 2018-07-12 00:25:16

How to display the number of likes of the top user of the VK group?

The script displays the user who, with the largest number of likes, put on the group wall (name, surname, avatar are displayed)

public function getLikerId()
    {
        global $config;

        $users = [];

        $time_to = time();
        if (!empty($config['like_interval']['to'])) {
            $time_to = strtotime($time_to);
        }

        $posts = $this->getPosts(-$config['group_id']);

        foreach ($posts as $post) {
            if ($post->date < strtotime($config['like_interval']['from']) || $post->date > $time_to) {
                continue;
            }

            $likes = $this->getLikes(-$config['group_id'], $post->id);

            foreach ($likes->users as $id) {
                if (isset($users[$id])) {
                    $users[$id]++;
                } else {
                    $users[$id] = 1;
                }
            }
        }

        arsort($users);
        $user_ids = array_keys($users);
        $user_id = array_shift($user_ids);
        return $user_id;
    }
 
    private function getLikes($owner_id = 1, $item_id = 1, $type = 'post')
    {
        return $this->api('likes.getList', [
            'owner_id' => $owner_id,
            'item_id'   => $item_id,
            'type'   => $type,
            ]);
    }

how to get the number of these likes, how much he put?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Payne, 2018-07-12
@YardalGedal

1. Go through all posts using the wall.get method - Bad .
2. Using the CallBack API , receive notifications about likes set by the user and save them on your server (preferably in a database) - Good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question