【问题标题】:Grant permission to an existing file on google drive api v3 in node js授予节点 js 中 google drive api v3 上现有文件的权限
【发布时间】:2020-08-28 08:26:01
【问题描述】:

在通过 google drive api v3 创建 csv 文件或电子表格后,我们需要授予使该文件在 google drive 中可见的权限。

【问题讨论】:

    标签: node.js csv google-drive-api


    【解决方案1】:
    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");
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 1970-01-01
      相关资源
      最近更新 更多