Saturday, 15 August 2015

google apps script - Drive PDF revision ids are being ignored -



google apps script - Drive PDF revision ids are being ignored -

this has come before, related google drive sdk: how exportlinks revisions in google drive api.

my problem isn't in getting exportlinks - ones provided api don't work.

here's modified version of "listing revisions" illustration advanced drive service documentation, logs exportlinks each revision of given fileid.

function listrevisions(fileid) { var revisions = drive.revisions.list(fileid); if (revisions.items && revisions.items.length > 0) { (var = 0; < 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.'); } }

logs

here sample logs test document has 2 "major" revisions. revision numbers provided explicitly in exportlinks.

[14-11-13 16:40:50:511 est] date: nov 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: nov 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, good. except links open same version of document... latest. (go ahead, seek them - document public.)

question: there format of exportlinks download specified revisions? (i.e. maybe 'revision' parameter should named else)

google engineers have reproduced problem using code shown below, , have raised internal bug study regarding this. while sample code in google apps script, problem in google drive itself.

you may track progress visiting , starring issue 4008 on google-drive-sdk issue tracker.

class="lang-js prettyprint-override">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); }); }); }

google-apps-script google-drive-sdk

1 comment:

  1. Since Google moved to its new Issue tracker, this issue has been renumbered as 36759589 and can be found here:
    https://issuetracker.google.com/issues/36759589

    ReplyDelete