R
R
rusgayfer2018-03-02 18:18:14
In contact with
rusgayfer, 2018-03-02 18:18:14

Error installing Callback API VK server?

Set up a community server with a POST request

$url = 'https://api.vk.com/method/groups.addCallbackServer';
                      $params = array(
                      'group_id' => $d['id_group'],
                      'url' => 'https://test.ru/callback/api.php?key=0aa3e5tugzw6k6hgsoda',   // Если что скрыл название своего сайта
                      'title' => 'Сервер', 
                      'access_token' => $d['token'],  // access_token 
                      'v' => '5.73',
                                     );

                      // В $result вернется id отправленного сообщения
                      $requestpost = file_get_contents($url, false, stream_context_create(array(
                      'http' => array(
                      'method'  => 'POST',
                      'header'  => 'Content-type: application/x-www-form-urlencoded',
                      'content' => http_build_query($params)
                                      )
                       )));

It turns out such an error.
5a996afb1b082827491804.png
I tried both GET requests and changed the file encodings, nothing helps, it is not installed via the API. And when I press confirm manually, everything works, the green checkmark is on. How to fix it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
VK API, 2018-03-03
@rusgayfer

For those who will later google:
if the callback server is added via the API, then the confirmation code must also be obtained via the API using the groups.getCallbackConfirmationCode method. It differs from the code in the web version of the site.

A
Alexander, 2018-03-02
@SilimAl

The server address is incorrect. Just https://server.ru/callback/api.php
But in the api.php itself, already write:

$confirmation_token = '58e46a05';
$data = json_decode(file_get_contents('php://input'));
switch ($data->type):
    case 'confirmation': echo $confirmation_token; break;
    case 'wall_post_new': реакция на событие; echo('ok'); break;
    ...
endswitch;

M
Maxim, 2018-03-02
Alexsev @MaxGoody

For using file_get_contents for requests, you can slap your hands :)

R
rusgayfer, 2018-03-03
@rusgayfer

I check like this:

$groupsgetCallbackConfirmationCode = json_decode(file_get_contents("https://api.vk.com/method/groups.getCallbackConfirmationCode?group_id={$cal['id_group']}&access_token={$cal['token']}&v=5.73"));		

// Строка для подтверждения адреса сервера из настроек Callback API 
//$confirmation_token = $cal['confirmation_token']; 
$confirmation_token = $groupsgetCallbackConfirmationCode->response->code;
// Версия API
$v = '5.73';

// Ключ сообщества для отправки сообщений (от его имени отправляются сообщения)
$token_message = 'токен';

//Получаем и декодируем уведомление 
$data = json_decode(file_get_contents('php://input')); 

//Проверяем, что находится в поле "type" 
switch ($data->type) { 
//Если это уведомление для подтверждения адреса... 
case 'confirmation': 
//...отправляем строку для подтверждения 
echo $confirmation_token; 
break;

But how to check when you insert the server manually, and not through the API?
that is, it must also check $confirmation_token = $cal['confirmation_token'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question