Answer the question
In order to leave comments, you need to log in
How to leave an entry on the wall of the Vkontakte group on behalf of an authorized user using the VK API?
Good afternoon,
is there a way to send a post to the group wall on behalf of the user. in an application like Website or StandAlone ? I have both created. StandAlone with a static Token. For the Website, the token changes after each authorization.
I
1. authorize the user on the test site
2. remember the ACCESS_TOKEN in the session
3. try to make an entry (review to the group on behalf of the authorized user is implied).
Unfortunately, in StandAlone , you can only send records through the API on behalf of the application owner.
I want to leave entries from an authorized user. Which is already authorized by meansVKontakte API like this:
if(!$this->code){
die('Неверный код');
}
$curl = curl_init();
$request_params = [
'client_id' => APP_ID,
'client_secret' => APP_SECRET,
'code' => $this->code,
'redirect_uri' => REDIRECT_URI,
];
curl_setopt($curl, CURLOPT_URL, URL_ACCESS_TOKEN.'?'. http_build_query($request_params));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
$ob = json_decode($result);
if($ob->access_token){
$this->setToken($ob->access_token);
$this->setUid($ob->user_id);
return true;
}
elseif($ob->error) {
$_SESSION['error'] = "ERROR";
return false;
}
public function sendMessage($description){
$access_token = $_SESSION['access_token'];
$request_params = [
'user_id' => 22557780,
'random_id' => mt_rand(20, 99999999),
'peer_id' => 22557780,
'domain' => 'mozart',
'chat_id' => 36,
'message' => $description,
'v' => '5.52',
'access_token' => $access_token
];
$url = 'https://api.vk.com/method/messages.send?'.http_build_query($request_params);
printArr(json_decode(file_get_contents($url)));
die();
$this->redirect('http://qas.loc');
}
Answer the question
In order to leave comments, you need to log in
To be honest, I did not really understand the essence of the issue, so I will go through all the possible points at once.
Through standalone applications, you can send records on behalf of any user who has authorized through your application.
The messages .*
methods can only be used through standalone applications. For websites and iFrame applications, posting via the wall.post method is available only through the confirmation window, and for standalone applications - without any problems.
I catch an error:
[error_code] => 15
[error_msg] => Access denied: no access to call this method .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question