[英]Cannot access files "shared" from service account via drive API?
I have a folder on google drive which was created via a service account, and shared with my user.我在谷歌驱动器上有一个文件夹,它是通过服务帐户创建的,并与我的用户共享。
My user has been granted "editor" permission of the folder.我的用户已被授予该文件夹的“编辑”权限。
What I need to do is access the list of files in the folder via the API with the service account impersionating my user.我需要做的是通过 API 使用模拟我的用户的服务帐户访问文件夹中的文件列表。
I've setup domain wide delegation and included the scopes:我已经设置了域范围的委托并包括范围:
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive
This query returns 100 results when acting as the service account , however when impersonating my user it returns 0 results.此查询在充当服务帐户时返回 100 个结果,但是在模拟我的用户时返回0 个结果。
const auth = new google.auth.GoogleAuth({
clientOptions: {
subject: 'myemail@myorganization.com'
},
keyFile: './token.json',
scopes: ['https://www.googleapis.com/auth/drive.file'],
});
drive.files.list({
q: "'THE_FOLDER_ID' in parents",
fields: 'nextPageToken, files(id, name, parents, appProperties)',
includeItemsFromAllDrives: true,
supportsAllDrives: true,
fields: '*',
spaces: 'drive'
}).then(response => {
console.log(response.data.files.length)
})
Turns out I needed to use the scope "https://www.googleapis.com/auth/drive" instead of "https://www.googleapis.com/auth/drive.file"结果我需要使用 scope“https://www.googleapis.com/auth/drive”而不是“https://www.googleapis.com/auth/drive.file”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.