我可以通过模拟访问用户文件。
当我调用教室获取方法(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 : 'mail_to_impersonate@gmydomain.edu.pe'
});
//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);
}
