为什么 Slack 的 files.list 端点 return 是一个空文件数组?

Why does Slack's files.list endpoint return an empty files array?

我想使用 Slack API 从我的工作中删除旧文件space,因为我们 运行 space 上传新文件.

我注册了一个应用程序,将其安装在目标工作上space,授予该应用程序 files:readfiles:write 权限,然后为该应用程序生成了一个机器人令牌前缀 xoxb.

使用此令牌,我使用 Postman 向 the files.list 端点发出了 GET 请求:

GET https://slack.com/api/files.list?token=xoxb-xxxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx&count=100&page=1&show_files_hidden_by_limit=true
HTTP/1.1
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 29879ef1-6da3-4863-8bb9-da8b4d5f740c
Host: slack.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

HTTP/1.1 200 OK
date: Sat, 09 Jan 2021 18:18:42 GMT
server: Apache
x-xss-protection: 0
pragma: no-cache
cache-control: private, no-cache, no-store, must-revalidate
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-slack-req-id: d972daab31ff4fe7a477eb3149ad5260
x-content-type-options: nosniff
referrer-policy: no-referrer
access-control-expose-headers: x-slack-req-id, retry-after
x-slack-backend: r
x-oauth-scopes: files:read,files:write
x-accepted-oauth-scopes: files:read
expires: Mon, 26 Jul 1997 05:00:00 GMT
vary: Accept-Encoding
access-control-allow-headers: slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags
content-encoding: gzip
content-length: 87
content-type: application/json; charset=utf-8
x-envoy-upstream-service-time: 444
x-backend: files_normal files_canary_with_overflow files_control_with_overflow
x-server: slack-www-hhvm-files-iad-jc2v
x-via: envoy-www-iad-4782, haproxy-edge-iad-y1wa
x-slack-shared-secret-outcome: shared-secret
via: envoy-www-iad-4782
{
  "ok": true,
  "files": [],
  "paging": {
    "count": 100,
    "total": 1803,
    "page": 1,
    "pages": 19
  }
}

如您所见,响应包含一个空的 files[] 数组,但是 paging 属性告诉我工作中有 1803 个文件space.

为什么我看不到工作中的任何文件space,即使我有适当的范围并得到 HTTP 200 响应?

我不知道这是否是 的答案,但这是一个解决方法:

  • 授予应用程序 channels:readchannels:join 范围
  • 调用 conversations.list 端点以获取工作区中的频道列表
  • 获取您想要为其列出文件的频道之一的 id 属性
  • 调用 conversations.join 端点将应用程序添加到频道
  • 调用 files.list 端点以获取该频道中的文件列表。

据推测,您可以遍历工作区中的每个 public 频道,加入每个频道,列出其文件,然后删除特定日期之前的文件。