M
M
Mozart2015-03-05 13:42:53
PHP
Mozart, 2015-03-05 13:42:53

REST API Yandex.Disk php how to add a remote file?

Hello. Has anyone come across working with the Yandex Disk API? You need to add the remote file to the disk. At the polygon, the request works fine.

define("TOKEN", "9193b.........e807aff33e");
$url = "https://cloud-api.yandex.net:443/v1/disk/resources/upload?path=12356.jpg&url=http%3A%2F%2Fwww.site.ru%2Fphoto.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
$header = array(
    'Accept: application/json',
    'Authorization: OAuth '. TOKEN ,

);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch);

For this request, Yandex responds with a 400 code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JacksScripts, 2015-12-27
@JacksScripts

The fact is that you do not close curl
, here is an example of the code that works for me:

define("TOKEN", "d.9e.........73bc..f");
$url = "https://cloud-api.yandex.net:443/v1/disk/resources/upload?path=fff.jpg&url=http://site.ru/image.png&disable_redirects=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
$header = array(
    'Accept: application/json',
    'Authorization: OAuth '. TOKEN ,

);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch);
curl_close($ch);
echo $result;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question