2017-02-01 149 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