C
C
cirega2016-02-15 18:11:17
PHP
cirega, 2016-02-15 18:11:17

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.
969feb45f6e5495ea550d348efac8b6d.png
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'];
?>

But I get such an error, can someone tell me how to do it, and is it even possible to invite to a group through the site?
{"error":{"error_code":15,"error_msg":"Access denied: no access to call this method","request_params":[{"key":"oauth","value":"1"} ,{"key":"method","value":"groups.invite"},{"key":"group_id","value":"######"},{"key":" user_id","value":"######"}]}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
littleguga, 2016-02-15
@cirega

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.htmlusing php, you can use this method on the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question