function createPermissionOffic(auth){
const drive = google.drive({version: 'v3', auth});
var fileId = rootFolderId;
var permissions = [
{
'type': 'user',
'role': 'writer',
'emailAddress': 'someemailaddress@gmail.com'
}
];
// Using the NPM module 'async'
async.eachSeries(permissions, (permission, permissionCallback)=> {
drive.permissions.create({
resource: permission,
fileId: fileId,
fields: 'id',
}, (err, res)=> {
if (err) {
// Handle error...
console.error(err);
permissionCallback(err);
} else {
console.log('Permission ID: '+ res)
permissionCallback();
}
});
}, (err)=> {
if (err) {
// Handle error
console.error(err);
} else {
// All permissions inserted
drive.permissions.insert(
{
'sendNotificationEmails': 'false'
});
}
});
I am getting below error : google drive API documentation does not elaborate much.here is the error I am getting. TypeError: drive.permissions.insert is not a function at async.eachSeries
I believe your goal as follows.
sendNotificationEmail: false
for Permissions: create method.drive.permissions.insert
is for Drive API v2. And in this case, when you run the script, an error occurs. In order to use sendNotificationEmail: false
, please use it to drive.permissions.create
.Rate limit exceeded
, when the array length of permissions
is large, such error might occur. So at first, as a test, how about checking whether the request works using a simple situation. In your sample script in your question, the array length of 1
is used. I think that how about checking the request using it?res.data.id
.rootFolderId
is used at var fileId = rootFolderId;
. When rootFolderId
is the root folder ID, an error like This file is never writable.
occurs. So please be careful this.When above points are reflected to your script, it becomes as follows.
const drive = google.drive({version: "v3", auth});
var fileId = "###"; // Please set the file ID or folder ID.
var permissions = [
{
type: "user",
role: "writer",
emailAddress: 'someemailaddress@gmail.com',
},
];
// Using the NPM module 'async'
async.eachSeries(
permissions,
(permission, permissionCallback) => {
drive.permissions.create(
{
resource: permission,
fileId: fileId,
fields: "id",
sendNotificationEmail: false, // <--- Added
},
(err, res) => {
if (err) {
// Handle error...
console.error(err);
permissionCallback(err);
} else {
console.log("Permission ID: " + res.data.id); // <--- Modified
permissionCallback();
}
}
);
},
(err) => {
if (err) {
// Handle error
console.error(err);
} else {
console.log("Done"); // <--- Modified
}
}
);