5

The Google Drive API v2 to v3 migration guide says:

The exportLinks field has been removed from files. To export Google Documents, use the files.export method instead.

I don't want to export (download) the file right away. "files.export" will actually download the file. I want a link to download the file, later. This was possible in v2 by means of the exportLinks.

How can I in v3 accomplish the same? If it is not possible, why was this useful feature removed?

Besides, (similar problem to above) downloadUrl was also removed, and the suggested alternative ("files.get with ?alt=media") downloads the file instead of providing a download link. This means there is no way in v3 to get a public short lived URL for a file?

EDIT:

there is no way in v3 to get a public short lived URL for a file?

For regular files, apparently yes.

This seems to work fine (a public short lived link to the file with its right name and contents): https://www.googleapis.com/drive/v3/files/ID?alt=media&access_token=TOKEN

For google apps files, no (not even private, as v2 exportLinks used to be).

https://www.googleapis.com/drive/v3/files/ID/exportmimeType=TYPEv&access_token=TOKEN

Similar to regular files, this URL is a short lived link to the file contents, but lacking of its right name.

BTW, I see the API is not behaving consistently: /drive/v3/files/FILEID delivers the right file name, but /drive/v3/files/FILEID/export does not.

I think the API itself should be setting the right Content-Disposition, as it is apparently doing when issuing a /drive/v3/files/FILEID call.

This file naming problem invalidates the workaround to the lack of ExportLinks in v3.

The v2 ExportLinks allowed me to link a file (which is not the same as getting its content right away). Anyone logged in and with the proper permissions was able to access it, and the link didn't needed any access_token, and it wasn't short lived. It was good and useful.

Building a link with a raw API call like /drive/v3/files/FILEID/export (with mandatory access_token) would be an close enough workaround (it is temporary and public, not the same as it was, anyway). However, the naming problem invalidates it.

In v2, regular files have a WebContentLink and google apps files have exportLinks. In v3 exportLinks are gone, and I don't see any suitable alternative to them.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
horacioj
  • 687
  • 1
  • 8
  • 25
  • 1
    Can you check this [link](https://developers.google.com/drive/v3/reference/files/export) – eisbach Apr 22 '17 at 00:37
  • @MuratGüner, "files.export" will download the file. I want a link to download the file, as it used to be in v2. A url to download the file (what you can have in v2) , and the file contents itself (what you get in v3 using files.export) are not the same thing. – horacioj Apr 22 '17 at 00:41
  • This statement from migration "The exportLinks field has been removed from files. To export Google Documents, use the files.export method instead." It means only way is files.export method. – eisbach Apr 22 '17 at 00:45
  • 1
    At the beginning of January 2019, I noticed that ``exportLinks`` was added to Drive API v3. You can see it at [the official document](https://developers.google.com/drive/api/v3/reference/files). It seems that those links are the same with those of v2. If you want to retrieve ``exportLinks``, please add it to ``fields``. If this was not what you want, I apologize. – Tanaike Jan 24 '19 at 05:50
  • Thank you very much for posting this question! This was the final bit of information I needed to implement a v3 Drive application. – NobleUplift Jun 18 '19 at 16:19

2 Answers2

3

Once you query for your file by id you can use the function getWebContentLink() to get the download link of the file (eg. $file->getWebContentLink() ).

  • In .NET it's a property called "WebContentLink" It returns a string – Ole EH Dufour Jan 02 '23 at 17:53
  • This works if you are logged in, however the getDownloadUrl() from v2 seemed to work with an API key. The webContentLink is a https://drive.google.com URL while the getDownloadUrl() from v2 returned a https://www.googleapis.com URL. – scorgn Apr 12 '23 at 19:29
0

I think you're placing too much emphasis on the word "method".

There is still a link to export a file, it's https://www.googleapis.com/drive/v3/files/fileIdxxxxx/export&mimeType=xxxxx/xxxxx. Make sure you URL encode the mime type.

Eg

https://www.googleapis.com/drive/v3/files/1fGBQ81haNU_nEiC5GITZD3bxT0ppL2LHg-C0ubD4Q_s/export?mimeType=text/csv&access_token=ya29.Gmo0BMvO-pVEPKsiD9j4D-NZVGE91MChRvwOcBSg3cTHt5uAClf-jFxcovQScbO2QQhwHS95eSGW1eQQcK5G1UQ6oI4BFEJJkntEBkgriZ14GbHuvpDL7LT2pKA--WiPuNoDDIuZMm5lWtlr

These links form part of the API, so the expectation is that you've written a client that sends authenticated requests, and deals with the response data. This explains why, if you simply paste the link into a browser without an access_token, it will fail. It also explains why the filename is export, ie. it isn't intended that your client would ever use a filename, but rather it should receive the data as a stream. This SO answer discusses the situation in more detail How to set name of file downloaded from browser?

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • I get 404 (Not Found), and I know the fileid is right. – horacioj Apr 22 '17 at 16:07
  • Works for me. Can you paste the link you used and confirm you're including the correct access token for the file you're trying to access. I've updated the answer with the link I just used to confirm it works – pinoyyid Apr 22 '17 at 19:17
  • 1
    Ahhh! access token was missing. It is all good now. Thanks. I've also verified I can do the same for regular files. i.e. https:// www.googleapis.com/drive/v3/files/ FILEID ?alt=media &access_token=ACCESSTOKEN. This is a good replacement for the now missing downloadUrl – horacioj Apr 23 '17 at 00:43
  • One more thing... The file I get from this URL is named "export". What should I add to the URL to get the actual item's name? – horacioj Apr 23 '17 at 00:50
  • If the answer is correct, you should accept it. I've updated it with a bit more info to deal with your supplementary question. – pinoyyid Apr 23 '17 at 05:45
  • I was aware of the Content-Disposition option. I'm also aware of these links being part of the API. I see also the API is not behaving consistently: /drive/v3/files/FILEID delivers the right file name, but /drive/v3/files/FILEID/export does not. Unfortunately I cannot accept the answer because it doesn't solve the problem. In v2 ExportLinks did what I needed. There is not suitable substitute in v3, The fact is, v3 has less functionality than v2. This is sad, but true. In my use case, I NEED a true link to the files, and this is not available in v3, as it was in v2. – horacioj Apr 23 '17 at 15:09
  • Please detail in exactly what way do you think the v2 files.export link and the v2 exportLink link are different? In a previous comment you said "it's all good now". The v3 API is a kinda dumbed down version of v2, and you're right that some functionality is missing (eg. etag). That's why v2 is still supported. – pinoyyid Apr 23 '17 at 17:06
  • In the comments I said "it's all good now" because I didn't noticed the file naming problem (this is, when exporting a file, its name is not preserved). I've edited the question adding some clarifications. – horacioj Apr 23 '17 at 18:26