【问题标题】:discord oauth2 api call returns "405: Method Not Allowed"discord oauth2 api 调用返回“405:不允许的方法”
【发布时间】:2021-04-06 09:25:58
【问题描述】:

我正在创建一个用户可以使用其 Discord 帐户登录的网站。

我正在进行如下所示的 API 调用:

https://discordapp.com/api/oauth2/token?grant_type=authorization_code&client_id=791748434310201344&client_secret=superSecretID&redirect_uri=mywebsite%2Fprotocols%2Fadd_discord.php&code=KI5LYgKj7QuO3oBkddXQW6SnJbg17K&scope=identify

我期待这样的回报:

{
  "access_token": "6qrZcUqja7812RVdnEKjpzOL4CvHBFG",
  "token_type": "Bearer",
  "expires_in": 604800,
  "scope": "identify"
}

但是,我得到了:

{"message": "405: Method Not Allowed", "code": 0}

我已经看Discord oauth2 documentation 有一段时间了,但我想不通。

【问题讨论】:

  • 验证您的获取值并查询您的数据库以匹配这些值;

标签: php oauth-2.0 discord


【解决方案1】:

确保您正在发出POST 请求,不允许使用其他方法(如GET)。

如果您运行下面的 sn-p,您可以看到 GET 收到“方法不允许”错误,而 POST 只是在抱怨无效的 client_id

fetch('https://discordapp.com/api/oauth2/token?grant_type=authorization_code&client_id=CLIENTID&client_secret=superSecretID&redirect_uri=http%3A%2F%2Flocalhost%2Fadd_discord.php&code=xxx&scope=identify', {
    method: 'GET'
  })
  .then(res => res.json())
  .then(res => console.log({
    method: 'GET',
    res
  }))
  
fetch('https://discordapp.com/api/oauth2/token?grant_type=authorization_code&client_id=CLIENTID&client_secret=superSecretID&redirect_uri=http%3A%2F%2Flocalhost%2Fadd_discord.php&code=xxx&scope=identify', {
    method: 'POST'
  })
  .then(res => res.json())
  .then(res => console.log({
    method: 'POST',
    res
  }))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 2011-03-04
    • 1970-01-01
    • 2013-03-21
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多