C
C
CrazyKing2020-07-31 12:25:12
PHP
CrazyKing, 2020-07-31 12:25:12

How to use a direct link from Yandex.disk correctly?

Good afternoon!
The essence of the problem:
There is a script:

$public_key = "https://yadi.sk/d/AvWmc-wb0fK1vw";  //публичная ссылка на Яндекс.Диск
$json_decode = json_decode(file_get_contents("https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key=".$public_key),true); //получаем прямую ссылку
$link = $json_decode[href]; //выбираем только ссылку из JSON

  echo '</br><a href="' . $link . '">Скачать</a>'; // выводим ссылку на скачивание


Everything seems to be fine, but when I try to follow the link, I get a 403 status in response:

5f23e22018656067756651.png

At the same time, if you just type the received link in the browser, it allows you to download the file without any problems, and after that the link starts working as it should.
The question is, is it possible to somehow bypass manual manipulations with the browser and download the file right away?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alekssamos, 2020-07-31
@alekssamos

https://getfile.dokpub.com/yandex/

R
Rufat Nuriev, 2020-11-07
@nrr

Yandex began to block frequent requests from sites.
The solution was to include the head meta tag in the html heading: This is so that your site does not transmit where the request for the picture or file comes from. An alternative is not to specify globally as mentioned above, but to specify rel="noreferrer" for each link, as in the example below:
<meta name="referrer" content="no-referrer" />

<a href="http://example.com/" rel="noreferrer">ssilka</a>

Our service https://getfile.dokpub.com/yandex/ implements exactly the same mechanism.
Related questions:
How to programmatically download a file from Yandex.Disk?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question