Google Apps 脚本和 Drive API v3 错误 400:writableFieldRequired

问题描述 投票:0回答:0

为什么即使包含可写属性(

Google Drive API v3 Comments
writableFieldRequired
),
comment
也会抛出
anchor
错误?

代码:

function testComment() {

  var doc = DocumentApp.getActiveDocument();
  var token = ScriptApp.getOAuthToken();

  var docId = doc.getId();
  var urlDriveCommentsV3 = 'https://www.googleapis.com/drive/v3/files/' + docId + '/comments?fields=id';

  var anchor = {
    'r': 'head',
    'a': [
      {
        'txt': {
          'o': 1,
          'l': 6
        }
      }
    ]
  };

  var commentv3 = {
    'content': 'This is a test comment 01',
    'anchor': anchor
  };

  var options = {
    'method': 'post',
    'headers': {
      'Authorization': 'Bearer '+  token,
      'Accept': 'application/json',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    'payload': commentv3,
    'muteHttpExceptions': true
  };

  var result = UrlFetchApp.fetch(urlDriveCommentsV3, options);

  Logger.log(result);
};

错误日志:

{
  "error": {
    "code": 400,
    "message": "At least one writable field must be specified in the resource body.",
    "errors": [
      {
        "message": "At least one writable field must be specified in the resource body.",
        "domain": "global",
        "reason": "writableFieldRequired"
      }
    ]
  }
}

参考资料:

Drive API v3

Google Apps 脚本

google-apps-script google-drive-api google-docs
© www.soinside.com 2019 - 2024. All rights reserved.