我在使用服务帐户密钥和使用drive.files.list API进行编码时遇到了问题,尽管我已经公开共享了所有文件,但我无法获取文件
const { google } = require('googleapis');
const drive = google.drive('v3');
const jwtClient = new google.auth.JWT(
client_email,
null,
private_key,
['https://www.googleapis.com/auth/drive']
);
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log("Successfully connected!");
}
});
// List Drive files.
drive.files.list({
auth: jwtClient,
// fields: "files",
includeRemoved: false,
spaces: 'drive'
}, (listErr, resp) => {
if (listErr) {
console.log(listErr);
return;
}
console.log("Result ========>", resp.data.files)
});
请帮助我。谢谢 :)
服务帐户不是您,它是虚拟用户。像任何用户一样,files.list将仅返回其有权访问的文件。那是它创建的文件和某人与它共享的文件。人们可能会认为每个人都可以访问公共文件。如果files.list返回了设置为public的Google驱动器上所有文件的列表,那将是一个巨大的列表,并且不是很有用。
通过将文件设置为公开(如果您具有文件ID),您将可以使用API密钥查看该文件。您将无法对其进行编辑,但可以执行一个文件。
采取服务帐户的电子邮件地址,然后转到Google云端硬盘,就可以像使用任何其他用户一样与服务帐户共享包含文件的文件夹。如果需要,您也可以与服务帐户单独共享每个文件。然后尝试做一个files.list。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句