Here is the working code:
$accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $vkAPI = new \BW\Vkontakte(['access_token' => $accessToken]); $publicID = -$group_id; // group_id $getURL = array( 'group_id' => $group_id, ); if($vkAPI->api("photos.getWallUploadServer",$getURL)){ // получаем upload_url $result = $vkAPI->api("photos.getWallUploadServer",$getURL); } else { echo "ERROR URI<BR>"; } $curl = curl_init(); //загружаем фото и получаем photo_id и owner_id $file = DIR_IMAGE.'0qDLZ0kw0I.jpg'; // путь к загружаемому файлу $file = curl_file_create($file, mime_content_type($file),pathinfo($file)['basename']); curl_setopt($curl, CURLOPT_URL, $result['response']['upload_url']); curl_setopt($curl, CURLOPT_POST, true); $charset = array( 'Content-Type' => 'multipart/form-data', 'charset' => 'utf-8', ); curl_setopt($curl, CURLOPT_HTTPHEADER, $charset ); curl_setopt($curl, CURLOPT_POSTFIELDS, ['file' => $file]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); $response_image = json_decode(curl_exec($curl)); curl_close($curl); $request_params = array( 'group_id'=>"$group_id", 'photo' => $response_image->photo, 'server' => $response_image->server, 'hash' => $response_image->hash, ); $getPhoto = $vkAPI->api("photos.saveWallPhoto",$request_params); $photo_id = $getPhoto['response'][0]['pid']; $owner_id = $getPhoto['response'][0]['owner_id']; $dataSend = array( // подготавливаем наш Post 'owner_id' => $publicID, 'message' => "I'm new Post!", 'attachments'=> "photo".$owner_id."_".$photo_id.", https://google.com/" // where photo_id = media_id ) ; if($vkAPI->api("wall.post",$dataSend)){ $vkAPI->api("wall.post",$dataSend); echo "Post добавлен!<BR>"; } else { echo "ERROR! Ищем ошибку<BR>"; }
Infa docks described, so I will not re-add. All good!
photos.getAllmethod and useidas<media_id>. - webDev_media_id, which must be inserted into attachments. Just how to do it? I'm trying to figure it out. If anyone has any experience, share w - ultimatum