M
M
Mors Clamor2018-10-19 17:38:42
API
Mors Clamor, 2018-10-19 17:38:42

VK longpoll, how to handle an event?

I want to create a simple bot - an answering machine.
I get a token for the community, I get a longpoll server iiiiii. That's all)
How do I store key, server and ts and how do I actually process responses?
file user_auth.php - the first authorization file

include "config.php";   
  header("Location:https://oauth.vk.com/authorize?group_ids=ид_группы&client_id=ид_клиента&redirect_uri=http://botrus.io/get_token.php&display=popup&scope=groups+manage+messages&response_type=code&v=5.85");
?>

The get_token.php file is the second file, everything is probably done wrong here
include "config.php";      
 if (isset($_GET["code"])) {
    $response = json_decode(curl("https://oauth.vk.com/access_token?client_id=" . APP_ID . "&client_secret=" . SECRET_KEY . "&redirect_uri=http://botrus.io/get_token.php&code=" . $_GET["code"]));
    if (isset($response -> access_token_144987289)) {
         $_SESSION["token"] = $response -> access_token_144987289;
         $_SESSION["auth"] = "true";    
        } 
    else {
        $_SESSION["auth"] = "false"; 
         header("Location:https://oauth.vk.com/authorize?client_id=6724385&redirect_uri=http://botrus.io/auth_user.php&display=popup&scope=groups&response_type=code&v=5.85");
        } 
        if ($_SESSION["token"]!=null) {
            header("Location:http://botrus.io/bot.php");
            echo "Токен: ".$_SESSION["token"];
            header("Location:http://botrus.io/bot.php");
        }
    }     
?>

And the bot itself
include "config.php";  
$event=json_decode(curl($_SESSION["server"]."?act=a_check&key=".$_SESSION["key"]."&ts=".$_SESSION["ts"]."&wait=25"));
$fd = fopen("hello.txt", 'w') or die("не удалось создать файл");
$str = "Пришло событие";
fwrite($fd, $str);
fclose($fd);
?>

But nothing works. Tell me please

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question