错误“允许类型字段是必需的".尝试通过Google Drive API创建权限时 [英] Error "permission type field is required" when attempting to create permission via Google Drive API

查看:68
本文介绍了错误“允许类型字段是必需的".尝试通过Google Drive API创建权限时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此处,尝试对Google云端硬盘中的现有文件创建新权限.

I adapted code from the Google Drive API Quickstart for Node.js found here to try and create a new permission on an existing file in Google Drive.

无论代码中有什么更改,即使我通过nc googleapis

No matter what I change in the code, I always get the same response saying The permission type field is required even though I've specified it via resource as mentioned in documentation for the npm googleapis client library and other examples I've found.

这是行不通还是我缺少明显的东西?

Is this just not working or am I missing something obvious?

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

    }

  });

}

code: 400,
errors: 
 [ { domain: 'global',
     reason: 'required',
     message: 'The permission type field is required.',
     locationType: 'other',
     location: 'permission.type' } ]

推荐答案

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

To anyone that's still looking at the answer, it needs to be formatted like this:

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

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

Google's APIs are using Axios for the HTTP client so it will be auto-stringified for you when using their methods :)

这篇关于错误“允许类型字段是必需的".尝试通过Google Drive API创建权限时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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