exportlink for Google drive api v3

Viewed 2994

I'm switching to the Google drive V3 apis and I'm not able to retrieve the stream to the document.

Goal: I want to push a google drive document to another location and I need to retrieve the stream of the file in order to use it to push it to the target.

I can't find a way to do it using Google Drive API V3 !

In V2, I used:

downloadUrl = file.ExportLinks[(string)ExportTable[file.MimeType]];

And then I could use something like:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(downloadUrl));

I don't find the equivalent in V3. I tried:

 var getfile = _service.Files.Get(file.Id).Execute();
 var request = _service.Files.Export(file.Id, getfile.MimeType);
 System.IO.Stream stream = request.ExecuteAsStream();

And the content of the stream is:

{
"error": {
 "errors": [
 {
"domain": "global",
"reason": "fileNotExportable",
"message": "Export only supports Google Docs."
}   ],
"code": 403,
"message": "Export only supports Google Docs."
}
}

Of course, we don't want to download it to a local file and then generate a new stream from the file cached locally. We want to remain entirely in memory.

Thanks for your help

2 Answers

You can see that in the Migrate to Drive v3 docs, it says that:

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

Check that page for other changes in v3 as well.

Related