Ian*_*Ian 4 javascript node.js slack-api slack
我正在尝试获取 Slack 中的私人频道列表(基于每个用户即可),但我在查看此信息时遇到问题。我最初将应用程序安装到 Slack 中的工作区中,并获得了表单中的 OAuth 令牌xoxp-4...........
。
应用程序 OAuth 令牌
当我尝试使用 slack API(节点 SDK)时,我只能获得公开列出的频道。
await new WebClient(`xoxp-4.....`)
.conversations
.list({ exclude_archived: true })
).channels
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用 Slack API 测试器来获取频道列表,我也会得到同样的结果。
用户 OAuth 令牌
我已遵循OAuth 2.0流程来获取给定用户(我自己)的令牌。我认为我已经正确完成了这一切(这是回复):
{
ok: true,
access_token: 'xoxp-4.........',
scope: 'identify,bot,commands,channels:history,groups:history,im:history,mpim:history,channels:read,emoji:read,groups:read,im:read,search:read,team:read,users:read,users:read.email,usergroups:read,users.profile:read,chat:write:user,chat:write:bot,links:read',
user_id: 'UD......',
team_name: '............',
team_id: '.......',
scopes: ['identify',
'bot',
'commands',
'channels:history',
'groups:history',
'im:history',
'mpim:history',
'channels:read',
'emoji:read',
'groups:read',
'im:read',
'search:read',
'team:read',
'users:read',
'users:read.email',
'usergroups:read',
'users.profile:read',
'chat:write:user',
'chat:write:bot',
'links:read'
]
}
Run Code Online (Sandbox Code Playgroud)
有趣的是,我发现如果我转到应用程序管理,这会为我提供完全相同的 OAuth 令牌(我假设是因为是我将应用程序安装到工作区)。
显然,因为它是相同的令牌,所以我仍然没有获得查看私人频道的权限,即使据我所知,我应该能够做作为用户可以做的一切?
谁能指出我可能缺少什么?
您没有获得私人频道的原因是您没有请求它们。
该conversations.list
方法仅默认返回公共频道。要获得私人频道,您需要相应地设置参数types
。例如types = public_channel,private_channel
。
与调用类似channels.list
。Channels.list
只会返回公共频道。如果您想获得私人频道,您需要致电groups.list
。(请注意,由于历史原因,私有频道在 API 中被称为组)。
一般来说,我建议使用conversations.list
,它更强大,也是获得所有类型对话的推荐方法。