生成谷歌驱动器链接的自定义直接下载链接 [英] generate custom direct download link for google drive link
问题描述
我找到了1个网站,但是我没有发现他在做什么。
下面是生成直接下载链接而不打开谷歌驱动器页面的网站。
https://links-safety.com/download.php?id=0B475ByfcR9n4a1JMVEZxQno2Tmc
0B475ByfcR9n4a1JMVEZxQno2Tmc是google档案,并以任何档案取代。
有谁能告诉我我该怎么做?我想像上面的网站一样的网页。
我试过这个网址,但它不工作。而不是开始下载它打开页面。
https://drive.google.com/uc?id=0BwSYfbOPSw89Rno4LTZpSGF6RUE
快速浏览一下它生成以下JavaScript。
< script>
setTimeout(function(){
window.location.href =https://doc-0o-a0-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/nemv3kbhggb02fn2933p80ec5vsi521t/1512345600000/10410701494873540224/* / 0B475ByfcR9n4a1JMVEZxQno2Tmc?e =下载;
},300);
< / script>
但是这个网址来自哪里?
有一点小窍门,当它要求在谷歌上确认时看到控制台,你可以看到它做了一个POST请求并返回一些json。
)]}'
{disposition:SCAN_CLEAN,downloadUrl:https://doc-0c-9k-docs.googleusercontent.com/docs/securesc/aonp7ed1gjmns5tl5di4fl0psa1cppk8 /16panrhf9etu7sqgddkaduij5anokf8t/1512345600000/17294955007197410767/17294955007197410767/0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3dXUGdtUUx3?e\\\=download\",\"fileName\":\"install.sh\",\"scanResult\":\"OK\",\"sizeBytes\":4936}
$ C $所以只要用PHP来嘲讽
对这个url做一个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',
...查看下面的通知
));
$ result = curl_exec($ ch);
$ object = json_decode(str_replace(')]} \'','',$ result));
exit(header('Location:'。$ object-> downloadUrl));
编辑(08-04-18 )
看起来像添加了一些额外的头文件,如果缺少它会抛出400错误请求。没有什么大不了的,当从你自己的驱动器下载文件时,通过查看请求标题来嘲笑它仍然很容易。我不愿意共享复制和粘贴解决方案,因为上述方法仍然有效,您只需添加一些标题,而且StackOverflow不是免费的编码服务,我也不需要维护我所写过的每一个答案。祝你好运。
I want to generate google drive direct download link without opening web page.
I have found 1 site which do same thing but I did not find how he is doing.
below is the site which generates direct download link without opening google drive page.
https://links-safety.com/download.php?id=0B475ByfcR9n4a1JMVEZxQno2Tmc
0B475ByfcR9n4a1JMVEZxQno2Tmc is google file and replace with any file.
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
解决方案 A quick look at the source of the site, it generates the following 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.
)]}'
{"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
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.
<?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)
Looks like some additional headers have been added, if missing it will throw a 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. Good luck.
这篇关于生成谷歌驱动器链接的自定义直接下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!