[英]generate custom direct download link for google drive link
I want to generate google drive direct download link without opening web page. 我想在不打开网页的情况下生成Google Drive直接下载链接。
I have found 1 site which do same thing but I did not find how he is doing. 我发现有1个网站做同样的事情,但我没有发现他的情况。
below is the site which generates direct download link without opening google drive page. 以下是无需打开Google驱动器页面即可生成直接下载链接的网站。
https://links-safety.com/download.php?id=0B475ByfcR9n4a1JMVEZxQno2Tmc https://links-safety.com/download.php?id=0B475ByfcR9n4a1JMVEZxQno2Tmc
0B475ByfcR9n4a1JMVEZxQno2Tmc is google file and replace with any file. 0B475ByfcR9n4a1JMVEZxQno2Tmc是Google文件,并替换为任何文件。
can anyone tell me how can I do that?I want to make same page like above site. 有人可以告诉我该怎么做吗?我想制作与上述网站相同的页面。
I tried this url but its not working. 我尝试了此网址,但无法正常工作。 instead of starting download it opens page. 而不是开始下载,它会打开页面。
https://drive.google.com/uc?id=0BwSYfbOPSw89Rno4LTZpSGF6RUE https://drive.google.com/uc?id=0BwSYfbOPSw89Rno4LTZpSGF6RUE
A quick look at the source of the site, it generates the following javascript. 快速浏览该网站的源代码,它将生成以下javascript。
<script>
setTimeout(function() {
window.location.href = "https://doc-0o-a0-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/nemv3kbhggb02fn2933p80ec5vsi521t/1512345600000/10410701494873540224/*/0B475ByfcR9n4a1JMVEZxQno2Tmc?e=download";
}, 300);
</script>
But where does that url come from? 但是该网址从何而来?
With a little fiddling and watching the console on when it does ask to confirm on google, you can see it does a POST request and returns some json. 稍作摆弄,然后看着控制台何时确实要求在Google上进行确认,您可以看到它发出了POST请求并返回了一些json。
)]}'
{"disposition":"SCAN_CLEAN","downloadUrl":"https://doc-0c-9k-docs.googleusercontent.com/docs/securesc/aonp7ed1gjmns5tl5di4fl0psa1cppk8/16panrhf9etu7sqgddkaduij5anokf8t/1512345600000/17294955007197410767/17294955007197410767/0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3dXUGdtUUx3?e\u003ddownload","fileName":"install.sh","scanResult":"OK","sizeBytes":4936}
So just mock that with PHP 因此,只需使用PHP进行模拟
Make a json POST request to that url, google will respond with the json, then just strip out )]}'
json decode it, then use a header to redirect to the file. 向该网址发出json POST请求,Google会以json响应,然后将( )]}'
json剥离掉,然后对其进行解码,然后使用标头重定向到该文件。
<?php
$id = '0B475ByfcR9n4a1JMVEZxQno2Tmc';
$ch = curl_init('https://drive.google.com/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
... see notice below
));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
exit(header('Location: '. $object->downloadUrl));
Edit (08-04-18) 编辑(08-04-18)
Looks like some additional headers have been added, if missing it will throw a 400 Bad Request. 看起来已经添加了一些其他标头,如果缺少标头,则会引发400 Bad Request。 No biggie, it's still easy to mock it by looking at the request headers when downloading a file from your own drive. 没什么大不了的,从您自己的驱动器下载文件时,通过查看请求标头仍然很容易模拟它。 I'm unwilling to share a copy&paste solution, as the above still works you just need to add some headers and StackOverflow is not a free coding service nor am I required to maintain every answer I've ever written. 我不愿意共享一个复制粘贴解决方案,因为上面的方法仍然有效,您只需要添加一些标头即可,而StackOverflow不是免费的编码服务,也不是我必须维护的所有答案。 Good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.