Node.js 授予对节点js中google drive api v3上现有文件的权限
通过google drive api v3创建csv文件或电子表格后,我们需要授予在google drive中显示该文件的权限Node.js 授予对节点js中google drive api v3上现有文件的权限,node.js,csv,google-drive-api,Node.js,Csv,Google Drive Api,通过google drive api v3创建csv文件或电子表格后,我们需要授予在google drive中显示该文件的权限 const google = require("googleapis").google; const credentials = require('path to your service account file credentials.json'); const async = require("async"); async
const google = require("googleapis").google;
const credentials = require('path to your service account file credentials.json');
const async = require("async");
async function filePermission(fileId, callback) {
const client = await google.auth.getClient({
credentials,
scopes: ["YOUR SCOPES"]
});
var permissions = [{ 'type': 'user', 'role': 'writer', 'emailAddress': 'test@example.com' }];
const drive = google.drive({ version: 'v3', auth: client });
async.eachSeries(permissions, function (permission) {
drive.permissions.create({
resource: permission,
fileId: fileId,
fields: 'id',
sendNotificationEmail: false,
}, function (err, resp) {
if (err) return console.log(err);
callback(resp);
});
}, function (err) {
if (err) {
console.error(err);
} else {
console.error("Permissions Granted");
}
});
}