我试图获取所有搜索结果,但是即使不包含任何搜索请求,也只能获取2个文件(只是尝试获取文件列表)。
const {google} = require('googleapis');
const keys = require('./keys.json');
const client = new google.auth.JWT(
keys.client_email,
null,
keys.private_key,
['https://www.googleapis.com/auth/drive.metadata.readonly']
);
client.authorize(function(err, tokens){
if(err){
console.log(err);
return;
} else {
console.log('Connected!');
gsrun(client);}
});
async function gsrun(cl){
const drive = google.drive({version: 'v3', auth:cl});
const resDrive = await drive.files.list({
pageSize: 5,
// q: "name contains 'test'",
spaces: 'drive',
});
const files = resDrive.data.files;
if (files.length) {
console.log('Files find:');
files.map((file) => {
console.log(`${file.name}, id: ${file.id}, link to file: https://drive.google.com/file/d/${file.id}/view`);
});
} else {
console.log('No files found.');
}
}
我在哪里错了?
答案 0 :(得分:0)
我终于想通了) 问题出在权限上-我必须与服务帐户共享所有文件才能获得访问权限。