wohali / oauth2-discord-new

New Discord Provider for the OAuth 2.0 Client
MIT License
118 stars 22 forks source link

How to get user avatar as image or URL? #14

Closed poyrazhancilar closed 6 years ago

poyrazhancilar commented 6 years ago

Is any code to get user avatar like:

$user->getAvatar();

Thanks.

HayateLaTech commented 6 years ago

please take a look at https://discordapp.com/developers/docs/resources/user#user-object https://discordapp.com/developers/docs/reference#image-formatting

wohali commented 6 years ago

@GameUx-Studios As mentioned in https://github.com/wohali/oauth2-discord-new/issues/3#issuecomment-367037473, this library only gives you the OAuth token.

Once you've used my library to get set up the scope and have gotten a bot token from Discord, make for example a new RestCord client using the token. You can then use it to retrieve the data you're looking for.

HayateLaTech commented 6 years ago

you don't need RestCord to get the user-avatar tho.. it's already available through your library by accessing the user variable for the avatar.

$user = $provider->getResourceOwner($token);

$avatar = "https://cdn.discordapp.com/avatars/" . $user->getId() . "/" . $user->getAvatar() . ".png";

should work therefor..

wohali commented 6 years ago

Oh right, I'd forgotten! Thanks for the reminder. :smile:

poyrazhancilar commented 6 years ago

you don't need RestCord to get the user-avatar tho.. it's already available through your library by accessing the user variable for the avatar.

$user = $provider->getResourceOwner($token);

$avatar = "https://cdn.discordapp.com/avatars/" . $user->getId() . "/" . $user->getAvatar() . ".png";

should work therefor..

I tried. But I get this errors:

[23-Oct-2018 19:43:03 Europe/Istanbul] PHP Fatal error: Uncaught Error: Call to undefined method Wohali\OAuth2\Client\Provider\DiscordResourceOwner::getAvatar() in /home/gameuxst/discordbotlist.gameuxst.com/login.php:58 Stack trace:

0 {main}

thrown in /home/gameuxst/discordbotlist.gameuxst.com/login.php on line 58

HayateLaTech commented 6 years ago

@GameUx-Studios it's $user->getAvatarHash() sorry ^^

poyrazhancilar commented 6 years ago

@GameUx-Studios it's $user->getAvatarHash() sorry ^^

Thank you :)

mrsaifullah52 commented 2 years ago

you don't need RestCord to get the user-avatar tho.. it's already available through your library by accessing the user variable for the avatar. $user = $provider->getResourceOwner($token); $avatar = "https://cdn.discordapp.com/avatars/" . $user->getId() . "/" . $user->getAvatar() . ".png"; should work therefor..

I tried. But I get this errors:

[23-Oct-2018 19:43:03 Europe/Istanbul] PHP Fatal error: Uncaught Error: Call to undefined method Wohali\OAuth2\Client\Provider\DiscordResourceOwner::getAvatar() in /home/gameuxst/discordbotlist.gameuxst.com/login.php:58 Stack trace: #0 {main} thrown in /home/gameuxst/discordbotlist.gameuxst.com/login.php on line 58

the url to get user avatar is https://cdn.discordapp.com/avatars/8917045513364434/102f0fe2cf4086daddab8bdd6af98d.png https://cdn.discordapp.com/avatars/{user.id}/{user.avatar}.png