PDF version identifiers for PDF files are ignored

This happened earlier with the Google Drive SDK: How do I get exportLinks for revision in the Google Drive API .

My problem is not getting exportLinks - just what the API provided does not work.

Here is a modified version of the "Version Listing" example from the Advanced Drive Service , which registers exportLinks for each revision of a given fileId .

 function listRevisions(fileId) { var revisions = Drive.Revisions.list(fileId); if (revisions.items && revisions.items.length > 0) { for (var i = 0; i < revisions.items.length; i++) { var revision = revisions.items[i]; var date = new Date(revision.modifiedDate); Logger.log('Date: %s, PDF exportLink: %s', date.toLocaleString(), revision.exportLinks[MimeType.PDF] ); } } else { Logger.log('No revisions found.'); } } 

Magazines

Here are sample logs for a test document with two "main" revisions. Version numbers are explicitly specified in exportLinks.

 [14-11-13 16:40:50:511 EST] Date: November 13, 2014 4:35:55 PM EST, PDF exportLink: https://docs.google.com/feeds/download/documents/export/Export?id=1V2zkXfyRGh_6gnCXtWlII6sxMQEDcLApRrEk-giIE2s&revision=28&exportFormat=pdf [14-11-13 16:40:50:512 EST] Date: November 13, 2014 4:37:51 PM EST, PDF exportLink: https://docs.google.com/feeds/download/documents/export/Export?id=1V2zkXfyRGh_6gnCXtWlII6sxMQEDcLApRrEk-giIE2s&revision=32&exportFormat=pdf 

So far so good. Except that these links open the MOST version of the document ... the last. (Come on, try - the document is open.)

Question: Is there any exportLinks format that really downloads the indicated fixes? (that is, perhaps the “revision” parameter should be called something else)

+6
source share
1 answer

Google engineers reproduced the problem using the code shown below and raised an internal bug report. Although the sample code is in Google Apps Script, the problem is in Google Drive itself.

You can track any progress by visiting and clicking Issue 4008 on google-drive-sdk problem tracking.

 function test() { var content = Utilities.newBlob('Apple', 'text/plain'); var file = { title: 'Test Document' }; file = Drive.Files.insert(file, content, { convert: true }); var doc = DocumentApp.openById(file.id); doc.getBody().appendParagraph('Banana'); doc.saveAndClose(); var oauthToken = ScriptApp.getOAuthToken(); var revisions = Drive.Revisions.list(file.id).items; revisions.forEach(function(revision) { // revision = revisions[]; Object.keys(revision.exportLinks).forEach(function(mimeType) { var link = revision.exportLinks[mimeType]; var response = UrlFetchApp.fetch(link, { headers: { Authorization: 'Bearer ' + oauthToken } }); var blob = response.getBlob(); var parts = blob.getName().split('.'); blob.setName(parts[0] + '-' + revision.id + '.' + parts[1]); DriveApp.createFile(blob); }); }); } 
+7
source

Source: https://habr.com/ru/post/978161/


All Articles