Answer the question
In order to leave comments, you need to log in
Attach image to post, VK API?
I can't attach an image to a post in a group.
In order:
I determine the path to the picture, pass the group ID without a minus and the token to the getWallUploadServer method
$photo_path = dirname(__FILE__).'/photo1.jpg';
$postData = array("file1" => '@'.$photo_path);
$getWallUploadServer = "https://api.vk.com/method/photos.getWallUploadServer?group_id=$group_id_for_method&access_token=$token&v=5.80";
$response = file_get_contents($getWallUploadServer);
$response = json_decode($response)->response->upload_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $response);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = json_decode(curl_exec($ch));
$server = $result->server;
$photo = $result->photo;
$hash = $result->hash;
$saveWallPhoto = file_get_contents("https://api.vk.com/method/photos.saveWallPhoto?access_token=$token&v=5.37&group_id=$group_id_for_method&server=$server&photo=$photo&hash=$hash");
$attachment = json_decode($saveWallPhoto)->response[0]->id;
header("Location: https://api.vk.com/method/wall.post?owner_id=$group_id&from_group=1&access_token=$token&attachments=photo{$group_id}_{$attachment}&v=5.37");
"One of the parameters specified was missing or invalid: invalid message param"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question