L
L
LNK2016-12-08 19:11:31
PHP
LNK, 2016-12-08 19:11:31

Why does an error occur when working with the VK API?

Greetings. The goal is to change the photo of the VK chat, for this, as it is written in the documentation , you need to do the following:

Upload the file to the upload_url address obtained in the previous paragraph by forming a POST request with the file field. This field must contain an image in multipart/form-data format.
To save the photo, call the messages.setChatPhoto method, passing in the file parameter the contents of the response field obtained in the previous step.

Here is my php code for post request:
$ch = curl_init($upload_url);
$curlfile = curl_file_create(__DIR__.DIRECTORY_SEPARATOR.'1.jpg');
$data = array("file"=>$curlfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
$content = curl_exec($ch);
Further, vk api, when executing the messages.setChatPhoto method, returns error 22: "Upload error: photo was not resized". What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lulzsec, 2016-12-08
@Lulzsec

This field must contain an image in multipart/form-data format.
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type:multipart/form-data"
));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question