Answer the question
In order to leave comments, you need to log in
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,
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question