gpt4 book ai didi

php - OAuth2 : Error 401 Unauthorized at PHP request with access_token (Discord API)

转载 作者:行者123 更新时间:2023-12-05 07:45:22 27 4
gpt4 key购买 nike

在用户通过他的 Discord 帐户授权登录后,我目前正在尝试通过 PHP 接收用户的 Discord 信息。授权和认证已经生效,所以access_token 有效

每次发送请求时,我都会收到 401 错误,如下所示:

{"code": 0, "message": "401: Unauthorized"}

PHP代码目前是这样的:

$second_curl = curl_init( 'https://discordapp.com/api/users/@me');  
curl_setopt( $second_curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt( $second_curl, CURLOPT_HTTPHEADER, array("Authorization: BEARER ".$secret->access_token));
$me = curl_exec( $second_curl );
echo $me;

用 $me 回应提到的错误响应。

我根本找不到解决方法。有人知道来自 OAuth2 服务器的奇怪响应吗?

最佳答案

我未经授权,因为我只使用了电子邮件范围,但没有使用身份范围。如果您遇到同样的问题,请务必使用 scope=identify+email!

关于php - OAuth2 : Error 401 Unauthorized at PHP request with access_token (Discord API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41746593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com