Repository navigation
Using the API
João Gabriel edited this page Aug 31, 2023
·
1 revision
import balbucio.discordoauth.DiscordOAuth;
DiscordOAuth oauthHandler = new DiscordOAuth(clientID: String, clientSecret: String, redirectUri: String, scope: String[]);
DiscordOAuth oauthHandler = new DiscordOAuth(clientID: String, clientSecret: String, redirectUri: String, scope: List<String>);
DiscordOAuth oauthHandler = new DiscordOAuth(clientID: String, clientSecret: String, redirectUri: String, scope: SupportedScopes[]);String authURL = oauthHandler.getAuthorizationURL(state: String);state will be ingored by passing null.
CustomRequest request = new CustomRequest(requestUri: String, state: String, scope: String[]);
CustomRequest request = new CustomRequest(requestUri: String, state: String, scope: List<String>);
CustomRequest request = new CustomRequest(requestUri: String, state: String, scope: SupportedScopes[]);
String authURL = oauthHandler.getAuthorizationURL(request: CustomRequest);state will be ingored by passing null.
import balbucio.discordoauth.model.TokensResponse;
TokensResponse tokens = oauthHandler.getTokens(code: String);
String accessToken = tokens.getAccessToken();
String refreshToken = tokens.getRefreshToken();TokensResponse tokens = oauthHandler.refreshTokens(refresh_token: String);import balbucio.discordoauth.DiscordAPI;
DiscordAPI api = new DiscordAPI(access_token: String);The following API fetch calls will throw IOException (HttpStatusException) when access is denied due to invalid scope or expired token.
Scope identity is required.
Scope email is required for email and verified values.
import balbucio.discordoauth.model.User;
User user = api.fetchUser();Scope guilds is required.
import balbucio.discordoauth.model.Guild;
List<Guild> guilds = api.fetchGuilds();Scope connections is required.
import balbucio.discordoauth.model.Connection;
List<Connection> connections = api.fetchConnections();Scope guilds.join is required.
Make sure you have a bot in your OAuth application and that this bot is in the guild you want to add members to, to learn more click here.
api.joinGuild(guild: Guild, user: User, botToken: String);
// You can create a guild using just the IDScope gdm.join is required.
This function has not yet been tested, so it is recommended not to add it to production. Feel free to test it out.
GroupChannel channel = new GroupChannel(id: String);
api.joinGuild(channel: GroupChannel, user: User);