slack api 请求代码

slack api request code

我正在尝试进行初始 GET 调用以检索令牌请求的代码。我已经搜索了几个小时,但我无法弄清楚为什么我会收到 CORS 错误。我在管理面板中设置了重定向 url 并包含在我的查询参数中。我也试过没有它。没有任何工作。

应该就这么简单吧?

fetch(`https://slack.com/oauth/authorize?scope=identity.basic&client_id=xxxxxxxxx.xxxxxxx`)
  .then(res => console.log(res))

错误

Fetch API cannot load https://slack.com/oauth/authorize?scope=identity.basic&client_id=148914445073.148918419105. Redirect from 'https://slack.com/oauth/authorize?scope=identity.basic&client_id=xxxxxxxx.xxxxxxxx' to 'https://slack.com/oauth/authorize?client_id=xxxxxx.xxxxx&scope=identity.basic&team=T4CSWD325' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

您需要将用户重定向到此页面,而不是通过获取异步加载页面内容:D

这是用户批准您的申请的页面,之后他们将被重定向到您指定的回调。

大多数应用程序使用 Add to Slack 按钮将其添加到他们的网站。

有关整个 OAuth 流程的更多信息,请参见此处:https://api.slack.com/docs/oauth