最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

尝试通过Google Drive API创建权限时出现错误“需要类型字段”

运维笔记admin11浏览0评论

尝试通过Google Drive API创建权限时出现错误“需要类型字段”

尝试通过Google Drive API创建权限时出现错误“需要类型字段”

我修改了来自Google Drive API Quickstart for Node.js的代码,发现here尝试为Google云端硬盘中的现有文件创建新权限。

无论我在代码中做了什么改变,我总是得到相同的回答说The permission type field is required,即使我已经通过resource指定它,如npm googleapis client library的文档和我发现的其他示例中所述。

这只是不起作用还是我错过了一些明显的东西?

Code to update permission

function updateFilePermissions(auth) {

  var drive = google.drive({
    version: 'v3',
    auth: auth
  });

  var resourceContents = {
    role: 'writer',
    type: 'user',
    emailAddress: '[email protected]'
  };

  drive.permissions.create({

    resource: resourceContents,
    fileId: aValidFileId,
    sendNotificationEmail: false,
    fields: 'id',

  }, function(err, res) {

    if (err) {

      // Handle error...
      console.error(err);

    } else {

      console.log('Permission ID: ', res.id);

    }

  });

}
回答如下:

对于那些仍在寻找答案的人来说,需要将其格式化为:

  {
          fileId: fieldID, // String
          resource": {
            role: putRoleHere, //String
            type: putTypeHere //String
          }

Google的API正在使用Axios作为HTTP客户端,因此在使用他们的方法时,它会自动为您字符串化:)

发布评论

评论列表(0)

  1. 暂无评论