驱动器PDF版本ID被忽略 [英] Drive PDF revision ids are being ignored

查看:98
本文介绍了驱动器PDF版本ID被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前出现过与Google Drive SDK相关的问题: Issue Tracker。

  function test(){
var content = Utilities.newBlob('Apple','text / plain');
var file = {
title:'测试文档'
};
file = Drive.Files.insert(文件,内容,{
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:{
授权:'Bearer'+ oauthToken
}
});
var blob = response.getBlob();
var parts = blob.getName()。split('。');
blob.setName(parts [0] +' - '+ revision.id +'。'+ parts [1]);
DriveApp.createFile(blob);
});
});
}


This has come up before, related to the Google Drive SDK: How do I get exportLinks for revisions in Google Drive API.

My problem isn't in getting the exportLinks - just that the ones provided by the API don't work.

Here's a modified version of the "Listing revisions" example from the Advanced Drive Service documentation, that logs the 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.');
  }
}

Logs

Here are sample logs for a test document that has two "major" revisions. The revision numbers are provided explicitly in the 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 those links open the SAME version of the document... the latest. (Go ahead, try them - the document is public.)

Question: Is there some format of exportLinks that will actually download the specified revisions? (i.e. maybe the 'revision' parameter should be named something else)

解决方案

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

You may track any progress by visiting and starring Issue Tracker.

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);
    });
  });
}

这篇关于驱动器PDF版本ID被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆