Answer the question
In order to leave comments, you need to log in
How to switch to api vk correctly?
after VK stopped supporting versions of api 3.0 and 4.0, the VK dynamic cover script stopped working, it displayed the last person who joined the group and the user who put more likes for a certain period of time, with the new one it turned out to find a solution, but with the "liker" no..(( returns incorrect answer: ok[ ]
what's wrong here?
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;
}
/**
* Getting posts
* @param integer $owner_id - owner post id
* @param integer $count - count posts
* @return object - vk posts array
*/
private function getPosts($owner_id = 1, $count = 100)
{
$res = $this->api('wall.get', [
'owner_id' => $owner_id,
'count' => $count,
]);
return $res;
}
/**
* Getting likes for post
* @param integer $owner_id - owner post id
* @param integer $item_id - post id
* @param string $type - type
* @return object - vk likes array
*/
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