2017-02-01 157 views
2

我有一個谷歌驅動器的問題。下載公開谷歌驅動器文件

鏈接前:

https://drive.google.com/uc?export=download&id=FILE_ID

工作得很好直到現在,:-(但現在不工作了,結果沒有發現錯誤404,但該文件存在,我可以上傳文件輕鬆地構建下載網址。

例如這個,公開文件。

https://drive.google.com/uc?export=download&id=1Hz4D52yKS0qPIUrMmeYzEl_16UpdPrGhJAwSV_EaM4Y

存在該文檔。

https://docs.google.com/document/d/1Hz4D52yKS0qPIUrMmeYzEl_16UpdPrGhJAwSV_EaM4Y/edit

我怎樣才能下載文件未經授權,我需要直接的聯繫。

謝謝!

+0

我不認爲這工作了它鏈接回谷歌驅動不再託管的網頁文件。 – DaImTo

+0

谷歌肯定做了一些改變。現在是什麼方式?我如何構建下載文檔的直接鏈接。 – user2842722

回答

4

下載網址適用於Drive中的文件。例如https://docs.google.com/uc?id=FILE_ID

問題是您試圖下載「Google文檔」而不是文件。

要下載Google文檔,您可以使用File export方法。通常,您可以使用UI菜單File > Download as...選項中列出的任何格式下載Google文檔。

+0

好的答案謝謝!!!,我不知道這一點。以及如何下載「Google文檔」。有什麼辦法嗎? – user2842722

+1

我已經更新了我的答案。我注意到你已經提出了幾個問題,但沒有接受任何答案。你應該看看[我應該怎麼做當有人回答我的問題?](http://stackoverflow.com/help/someone-answers):) –

+0

我跟着搜索解決方案。用api我還沒有做到它。我需要將我自己的服務器連接到googleapi,而無需客戶端事件。我必須下載沒有客戶端身份驗證的文件在谷歌。這可能需要gsuit嗎?感謝!!! + – user2842722

0

我的解決辦法:

require_once '../autoload.php'; 
 
$user_to_impersonate = 'XXXXXXXXX'; 
 
putenv('GOOGLE_APPLICATION_CREDENTIALS='. __DIR__ .'/service-account.json'); 
 
$client = new Google_Client(); 
 
$client->useApplicationDefaultCredentials(); 
 
$client_email = '[email protected]'; 
 
$client->setSubject($client_email); 
 
$client->setScopes(array('https://www.googleapis.com/auth/drive')); 
 
$driveservice = new Google_Service_Drive($client); 
 
//var_dump($driveservice); 
 
$parameters = array(); 
 
if (isset($pageToken)) { 
 
    $parameters['pageToken'] = $pageToken; 
 
} 
 
$files = $driveservice->files->listFiles($parameters); 
 
$fileId = 'XXXXXXXXXXXXXXXXXXXX'; 
 
$file = $driveservice->files->export($fileId, 'application/pdf', array(
 
    'alt' => 'media')); 
 
$size  = $file->getBody()->getSize(); 
 
$content = $file->getBody()->read($size); 
 
header('Content-Type: application/octet-stream'); 
 
header("Content-Transfer-Encoding: Binary"); 
 
header("Content-disposition: attachment; filename=\"XXXX.pdf\""); 
 
echo $content;

+0

https://milanaryal.com/direct-linking-to-your-files-on-dropbox-google-drive-and-onedrive/ – user2842722