Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php discord oauth2 api调用返回;405:不允许使用“方法”;_Php_Oauth 2.0_Discord - Fatal编程技术网

Php discord oauth2 api调用返回;405:不允许使用“方法”;

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

我正在制作一个网站,用户可以使用他们的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"
}
我期待着这样的回报:

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值并查询数据库以匹配值;