谷歌驱动器链接的直接下载链接

时间:2018-03-13 10:13:44

标签: php google-drive-api

<?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));

我尝试使用此代码成功生成谷歌驱动器直接下载链接但未成功打开网页,但它今天无效:

2 个答案:

答案 0 :(得分:0)

<?php 

$id = '1IE2K47kVpcIUpLXDjtOcveiTnH9d4PUR';

$kntl = 'https://drive.google.com/uc?export=download&confirm=Ss_7&id='.$id.'';


    function downlah($url){
     $data = curl_init();
     curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($data, CURLOPT_URL, $url);
     $hasil = curl_exec($data);
     curl_close($data);
     return $hasil;
}
$dnanaoid =  downlah($kntl);

 $lnacoisncis = explode('<A HREF="', $dnanaoid);

$sdcpajpo = explode('">', $lnacoisncis[1]);


echo $directlink = $sdcpajpo[0]; //DIRECT LINK
?>

答案 1 :(得分:-1)

谷歌驱动视频共享链接下载链接转换

$download_link = preg_replace('/\/file\/d\/(\w+)\/view\?usp=sharing/',"/uc?export=download&id=$1", $sharing_file_name)