【问题标题】:Google Drive API: How do I list all files in a shared folder?Google Drive API:如何列出共享文件夹中的所有文件?
【发布时间】:2020-04-01 18:22:15
【问题描述】:

我有一个 google 服务帐户,并且我已成功将文件上传到共享文件夹(即,我使用普通 google 帐户创建了一个文件夹,与服务帐户共享,并将文件上传到该共享文件夹)。

当我用我的普通 google 帐户打开这个共享文件夹时,我可以看到由 google 服务帐户创建的文件。但是,当我从我的普通 google 帐户在共享文件夹中创建另一个文件时,当我拉文件列表时它确实显示。

我在做:

  // ???? does not work
  const results = await drive.files.list({
    corpora: 'allDrives', // just in case, don't know if this makes a difference
    includeItemsFromAllDrives: true,
    supportsAllDrives: true,
  });

  console.log(results.data.files);

使用节点 SDK 48(即"googleapis": "^48.0.0"


无论服务帐户是否创建了该文件,我如何让此服务帐户提取所有此文件夹中的共享文件?

【问题讨论】:

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


    【解决方案1】:

    我的头在墙上撞了一会儿后才明白。

    我有这个:

      const client = await google.auth.getClient({
        credentials: {/* ... */},
        //                                     ? WRONG ?
        scopes: 'https://www.googleapis.com/auth/drive.file',
      });
    

    只需将范围替换为:

      const client = await google.auth.getClient({
        credentials: {/* ... */},
        //                              ✅ Correct ?
        scopes: 'https://www.googleapis.com/auth/drive',
      });
    

    我不确定扩大范围是否正是你想要的,但似乎这个问题与范围有关,所以如果你遇到这个问题,start there

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多