Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 授予对节点js中google drive api v3上现有文件的权限_Node.js_Csv_Google Drive Api - Fatal编程技术网

Node.js 授予对节点js中google drive api v3上现有文件的权限

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

通过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 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");
        }
    });
}