在获得用户授权后,如何获得有关该用户的一些信息,我需要获取其服务器列表。我正在使用RestCord和oauth2-discord-new库,但是这些库不允许这样做。如何使用php做到这一点?
我尝试过的事情:
$provider = $discord->provider;
if (!Yii::$app->request->get('code')) {
$options = [
'scope' => ['identify', 'email', 'guilds']
];
$authUrl = $provider->getAuthorizationUrl($options);
return $this->redirect($authUrl);
} else {
$token = $provider->getAccessToken('authorization_code', [
'code' => Yii::$app->request->get('code')
]);
$discord = new DiscordClient(['token' => $token->getToken()]);
$discord->user->getCurrentUser([]); // Return 401 UNAUTHORIZED
}
答案 0 :(得分:0)
我看了restcord的源代码。还找到了参数tokenType
。关于它,文档中没有任何内容,但是如果您将其安装在OAuth中,则该库将在用户模式下而不是在bot下运行。如何正确使用它:
$discord = new DiscordClient([
'token' => 'userToken',
'tokenType' => 'OAuth'
]);
我花了很多时间来寻找解决这个问题的方法,但我对此感到非常惊讶,因为该参数未写在官方文档中。我希望这可以节省您的时间!