Closed MoonieGZ closed 6 years ago
Hi @LeafyDev ,
Sure thing. Start here:
https://github.com/wohali/oauth2-discord-new#sample-authorization-code-flow
and when you get to Step 1, add your options to the authUrl
constructor. Here's an example:
if (!isset($_GET['code'])) {
// Step 1. Get authorization code
$options = [
// add more scopes here if you need them
'scope' => ['bot', 'guilds', 'connections', 'identify', 'email']
];
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
// rest of the sample code is unchanged
...
Hope this helps!
I have done this but it's getting the data after that that I can't seem how to do...
@LeafyDev This is just an OAuth library for Discord. If you need to use the REST endpoints for Discord, you still need something like RestCord.
Once you've used my library to get set up the scope and have gotten a bot token from Discord, make a new RestCord client using the token. You can then use it to retrieve the data you're looking for.
Does that help?
Aaaaah, yes indeed, I see now.
Thanks for the pointers!
Hello again! I've been trying and trying to get it to work, and I just can't... I get 401'd by discord API, I'm getting a token successfully, but creating a discord client with restcord doesn't work, have you tried this personally? Since people on the restcord discord haven't answered my questions...
Yup, I've written a full integration between a fully-featured PHP forum website and Discord using my interface + Restcord.
You need to register a bot through the Discord API, join that bot to your server, and then use it to do some of the heavy lifting for you.
You can see an example of joining a user to a guild instance over here: https://github.com/wohali/oauth2-discord-new/issues/4#issuecomment-372379756
I'm getting slightly further, I thought you had to use the token generated by the oauth login with the restcord client, yet you use your bots token, so I tried that... Getting a little but further, but the scopes don't seem to give me anything...
This returns "NULL" email and 0 connections from getUserConnections();
I would ask the people at restcord but nobody seems to answer...
You need the token generated by the OAuth login to get that user's details and to forcibly join them to your guild without an invite code.
Once you have the token with my library:
$user = $provider->getResourceOwner($token);
$this->discord_id = $user->getId();
$this->username = $user->getUsername();
$this->discriminator = $user->getDiscriminator();
gets you the basics.
Hi, not quite sure how to contact you about this, you have the most up to date PHP oauth2 for discord I could find so I'm hoping you'll be able to help.
I'm trying to use the guilds and connections scopes to store in a bots database rather than having the user type out all their links for social stuff for example.
The guilds scope would be useful to have to check which guilds the user has
manage_server
on.Yet I can't find these in code anywhere, and my understanding of PHP isn't enough for this.. Any pointers?