Answer the question
In order to leave comments, you need to log in
How to invite a user to a Vkontakte group via vk api in PHP?
Good afternoon. I have a question, how to invite a user to a Vkontakte group via vk api in PHP? Created a standalone application.
Wrote this code
<?session_start();?>
<a href="https://oauth.vk.com/authorize?client_id=######&display=page&redirect_uri=http://user4.######.tmweb.ru&scope=wall,friends,offline,groups&response_type=code&v=5.45">Получить доступ</a>
<?php
if($_GET['code']){
$code = $_GET['code'];
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, 'https://oauth.vk.com/access_token');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "client_id=5295771&client_secret=7rI7QNkNcHvzut59V7Sg&redirect_uri=http://user4.######.tmweb.ru&code=" . $code);
$out = curl_exec($curl);
curl_close($curl);
}
$access_token = json_decode($out);
if($access_token->access_token){
$_SESSION['access_token'] = $access_token->access_token;
}
}
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, 'https://api.vk.com/method/groups.invite');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "group_id=######&user_id=######&access_token=" . $_SESSION['access_token']);
$out = curl_exec($curl);
curl_close($curl);
}
echo $out;
echo $_SESSION['access_token'];
?>
Answer the question
In order to leave comments, you need to log in
Carefully read the documentation, VK has nowhere to describe it in more detail. groups.invite
method :
Then you read about Standalone authorization and you see that redirect_url must be redirect_uri=https://oauth.vk.com/blank.html
. If you can pull access_token from redirect_uri=https://oauth.vk.com/blank.html
using php, you can use this method on the site.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question