错误"权限类型字段是必需的"尝试通过Google云端硬盘API

时间:2018-02-12 17:16:41

标签: node.js google-drive-api

我根据找到here的Node.js的Google云端硬盘API快速入门代码尝试为Google云端硬盘中的现有文件创建新权限。

无论我在代码中更改了哪些内容,我都会得到相同的回复The permission type field is required,即使我已经通过resource指定了它,如npm {{1}的文档中所述} client library以及我发现的其他例子。

这是不起作用还是我遗漏了一些明显的东西?

更新权限的代码



googleapis




来自Google Drive API

的回复
function updateFilePermissions(auth) {

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

  var resourceContents = {
    role: 'writer',
    type: 'user',
    emailAddress: 'user@example.com'
  };

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

    }

  });

}

1 个答案:

答案 0 :(得分:0)

对于仍在寻找答案的任何人,都需要采用以下格式:

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

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

相关问题