我可以通过模拟来访问用户文件。
[当我调用教室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);
}
teacherFolder id
之外还返回ownerId
ownerId
用作userId
的userProfiles.get以检索emailAddress