【问题标题】:Google Drive API v3 files.list not returning all filesGoogle Drive API v3 files.list 未返回所有文件
【发布时间】:2019-09-21 20:26:25
【问题描述】:

我试图获取所有搜索结果,但即使不包含任何搜索请求,也只能获取 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.');
    }
}

我哪里错了?

【问题讨论】:

  • 由于我们不知道实际存在哪些文件或它们的状态是什么,因此我们无法知道您看到的结果是否正确,或者您期望看到的结果
  • 对不起,有很多不同格式的文件。

标签: javascript node.js google-drive-api


【解决方案1】:

我终于想通了) 问题在于权限 - 我必须与服务帐户共享所有文件才能获得访问权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 2021-11-09
    相关资源
    最近更新 更多