Php discord oauth2 api调用返回;405:不允许使用“方法”;
我正在制作一个网站,用户可以使用他们的Discord帐户登录 我正在进行一个API调用,如下所示:Php discord oauth2 api调用返回;405:不允许使用“方法”;,php,oauth-2.0,discord,Php,Oauth 2.0,Discord,我正在制作一个网站,用户可以使用他们的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
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"
}
我期待着这样的回报:
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}
我已经看了一段时间了,但我想不出来。请确保您正在发出
POST
请求,其他方法(如GET
)是不允许的
如果您运行下面的代码段,您可以看到使用GET
您收到了一个“methodnotallowed”错误,而使用POST
它只是在抱怨无效的客户端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', {
方法:“获取”
})
.then(res=>res.json())
。然后(res=>console.log({
方法:“GET”,
物件
}))
取('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', {
方法:“发布”
})
.then(res=>res.json())
。然后(res=>console.log({
方法:“POST”,
物件
}))
验证get值并查询数据库以匹配值;