Google云端硬盘不知道要模拟哪个用户

问题描述 投票:-1回答:1

我可以通过模拟来访问用户文件。

[当我调用教室get方法(https://developers.google.com/classroom/reference/rest/v1/courses/get)时,将检索驱动器ID文件夹,并使用此fileId来调用驱动器api并获取文件许可权,但....此时,我不知道不知道谁是用户(电子邮件),所以我可以模拟它。

提示:教室所有者并不总是驱动器文件夹所有者。

是否可以在不冒充用户的情况下访问文件? (因为我不知道)。

如果我不冒充我会得到404。

一个是将文件共享到服务帐户,但是太多的文件太多了。

谢谢。

    try {
        let jwtClient = new google.auth.JWT({
            email : privatekey.client_email,
            key   : privatekey.private_key,
            scopes : [
                'https://www.googleapis.com/auth/drive.file',
                'https://www.googleapis.com/auth/drive',
                'https://www.googleapis.com/auth/drive.metadata',
                'https://www.googleapis.com/auth/drive.metadata.readonly',
                'https://www.googleapis.com/auth/drive.photos.readonly',
                'https://www.googleapis.com/auth/drive.readonly'
            ]
            //, subject : '[email protected]'
        });
        //console.log(jwtClient);
        jwtClient.authorize(function (err, tokens) {
            if (err) {
              console.log(err);
              return;
            } else {
              console.log("Successfully connected!");
            }
        });
        let drive = google.drive({ version: 'v3', auth: jwtClient });
        let params = {
            fileId : 'the_classroom_teacherFolder.id'
        };
        drive.files.get(params, (err, res) => {
            if(err) {
                console.log('err:', err);
            } else {
                console.log('res:', res.data);
            }
        });
    } catch (error) {
        console.log(error);
    }

enter image description here

google-drive-api impersonation service-accounts
1个回答
0
投票
    [当您使用courses.get时,该方法使您除了teacherFolder id之外还返回ownerId
  • 现在,您可以将此ownerId用作userIduserProfiles.get以检索emailAddress
  • 这是您可以用于模拟的电子邮件地址
  • 课程所有者应始终有权访问相应课程的教师文件夹
© www.soinside.com 2019 - 2024. All rights reserved.