$url = json_decode($url)->response->upload_url;
<?php
// Только STANDALONE TOKEN
$token = 'token';
$group_id = 'id';
$album_id = 'id';
$v = '5.62'; //версия vk api
$image_path = dirname(__FILE__).'/111.jpg';//путь до картинки
$post_data = array("file1" => '@'.$image_path);
// получаем урл для загрузки
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id=".$album_id."&group_id=".$group_id."&v=".$v."&access_token=".$token);
$url = json_decode($url)->response->upload_url;
//print_r($url);
// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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, $post_data);
$result = json_decode(curl_exec($ch),true);
//print_r($result);
// сохраняем
$safe = file_get_contents("https://api.vk.com/method/photos.save?server=".$result['server']."&photos_list=".$result['photos_list']."&album_id=".$result['aid']."&hash=".$result['hash']."&gid=".$group_id."&access_token=".$token);
$safe = json_decode($safe,true);
print_r($safe);
// итог
?>
$url = json_decode($url)->response->upload_url;
$url = json_decode($url)->upload_url;
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&access_token={$token}");
$url = json_decode($url)->upload_url;
<?php
// Только STANDALONE TOKEN
$token = 'token';
$group_id = 'id';
$album_id = 'id';
$v = '5.62'; //версия vk api
$image_path = dirname(__FILE__).'/111.jpg';//путь до картинки
$post_data = array("file1" => '@'.$image_path);
// получаем урл для загрузки
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&access_token={$token}");
$url = json_decode($url)->upload_url;
//print_r($url);
// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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, $post_data);
$result = json_decode(curl_exec($ch),true);
//print_r($result);
// сохраняем
$safe = file_get_contents("https://api.vk.com/method/photos.save?server=".$result['server']."&photos_list=".$result['photos_list']."&album_id=".$result['aid']."&hash=".$result['hash']."&gid=".$group_id."&access_token=".$token);
$safe = json_decode($safe,true);
print_r($safe);
// итог
?>
print_r(json_decode($url));
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&access_token={$token}");
Ошибки пропали. Остались только проблемы с загрузкой, выдаёт:
Array ( [error] => Array ( [error_code] => 8 [error_msg] => Invalid request: v (version) is required [request_params] => Array ( [0] => Array ( [key] => oauth [value] => 1 ) [1] => Array ( [key] => method [value] => photos.save ) [2] => Array ( [key] => server [value] => ) [3] => Array ( [key] => photos_list [value] => ) [4] => Array ( [key] => album_id [value] => ) [5] => Array ( [key] => hash [value] => ) [6] => Array ( [key] => gid [value] => тут_id_группы ) ) ) )
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&v={$v}&access_token={$token}");
json_decode($url);
ошибка, у которой нет параметра upload_url. Ошибка с кодом 15. Почитать можно тут эта ошибка фактически возможна из-за недостатка разрешений токена?Скорее всего
$url = json_decode($url)->response->upload_url;
<?php
// Только STANDALONE TOKEN
$token = 'token';
$group_id = 'id';
$album_id = 'id';
$v = '5.62'; //версия vk api
$image_path = dirname(__FILE__).'/111.jpg';//путь до картинки
$post_data = array("file1" => '@'.$image_path);
// получаем урл для загрузки
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&v={$v}&access_token={$token}");
$url = json_decode($url)->response->upload_url;
print_r(json_decode($url));
print_r($url);
// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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, $post_data);
$result = json_decode(curl_exec($ch),true);
print_r($result);
// сохраняем
$safe = file_get_contents("https://api.vk.com/method/photos.save?server=".$result['server']."&photos_list=".$result['photos_list']."&album_id=".$result['aid']."&hash=".$result['hash']."&gid=".$group_id."&access_token=".$token);
$safe = json_decode($safe,true);
print_r($safe);
// итог
?>
$safe = file_get_contents("https://api.vk.com/method/photos.save?v={$v}&server={$result['server']}&photos_list={$result['photos_list']}&album_id={$result['aid']}&hash={$result['hash']}&gid={$group_id}&access_token={$token}");
{$result['photos_list']}
print_r($result);
что показывает? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$result = json_decode(curl_exec($ch),true);
print_r($result);
$url = 'https://pp.userapi.com/c837420/v837420161/740a/GEjykJJjhkA.jpg';
$dir = __DIR__ . "/image";
$name = '1.jpg';
copy($url, $dir . DIRECTORY_SEPARATOR . $name);
<?php
$token = 'token';
$group_id = 'id';
$album_id = 'id';
$v = '5.62';
$url = 'https://pp.userapi.com/c837420/v837420161/740a/GEjykJJjhkA.jpg';
$dir = __DIR__ . DIRECTORY_SEPARATOR . "image";
$name = '1.jpg';
$imgfullname = $dir . DIRECTORY_SEPARATOR . $name;
copy($url, $imgfullname);
$post_data = array("file1" => new CurlFile($imgfullname));
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$album_id}&group_id={$group_id}&v={$v}&access_token={$token}");
$url = json_decode($url)->response->upload_url;
print_r(json_decode($url));
print_r($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data; charset=UTF-8'));
$result = json_decode(curl_exec($ch), true);
print_r($result);
$safe = file_get_contents("https://api.vk.com/method/photos.save?server={$result['server']}&photos_list={$result['photos_list']}&album_id={$result['aid']}&hash={$result['hash']}&gid={$group_id}&access_token={$token}&v={$v}");
$safe = json_decode($safe, true);
print_r($safe);
?>