J
J
Jebati2017-05-20 16:48:10
In contact with
Jebati, 2017-05-20 16:48:10

[VK API] How to send large messages?

Hello.
I ran into such a problem, when sending long messages via GET to the VK API, the service simply gives an error 400.
I don’t really want to cut all this into several messages, so the question is: how to send VK API messages via POST or are there any other then the options?
*(When sending about 700 characters, it is no longer sent).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-05-20
@Jebati

“make sending VK API messages via POST” - this is exactly the solution.
Upd. More or less like this:

$params = array(
    'user_id'       => $uid,
    'message'       => $long_message,
    'random_id'     => rand(1E9, 9E9)
    'access_token'  => $token,
    'v'             => 5.64,
);

$ch = curl_init( 'https://api.vk.com/method/messages.send');

curl_setopt_array( $ch, array(
    CURLOPT_POST            => TRUE,
    CURLOPT_POSTFIELDS      => $params,

    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_SSL_VERIFYPEER  => FALSE,
    CURLOPT_SSL_VERIFYHOST  => FALSE,
    CURLOPT_CONNECTTIMEOUT  => 10,
    CURLOPT_TIMEOUT         => 10,
));

$result = curl_exec( $ch);

$data = json_decode( $result);

$message_id = $data['response'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question