Need some help,
Using Wohali OAuth2 Client then Restcord to get actual content from the user logged.
But for some reason, i can't get it to list the roles for the user logged in.
Says "Message: There was an error executing the listGuildMembers command: Client error: GET https://discordapp.com/api/v6/guilds/{guild_id}/members?limit=1 resulted in a 401 UNAUTHORIZED response:"
The documentation is a bit lacking and i have spent a number of hours trying to get it sorted out.
use RestCord\DiscordClient;
$provider = new \Wohali\OAuth2\Client\Provider\Discord([
'clientId' => '{client_id}',
'clientSecret' => '{client_secret}',
'redirectUri' => '{redirect_uri}'
]);
$options = ['state' => 'CUSTOM_STATE', 'scope' => ['identify', 'email', 'guilds']];
if (!isset($_GET['code'])) {
// Step 1. Get authorization code
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
// Step 2. Get an access token using the provided authorization code
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
}
$user = $provider->getResourceOwner($token);
$client = new DiscordClient(['token' => $token->getToken(), 'tokenType' => 'OAuth']);
$roles = $client->guild->listGuildRoles(['guild.id' => {guild_id}]);
var_dump($roles);
I have removed the clientId, secret, guild id and such but they are valid, since the example on auth from Wohali works and shows my info when logged in.
Thanks in advance for any tips / help / ideas.