[BEGINNER] Authentication for Java App

Hi guys, im starting to programing with this API and i want to make an Android apk, but first i try the code i want to use in Java mode. I was able to get some information with the API but the problem was when i try to get de Subscribers of an User. After searching i discover that i have to make an Authentication page, so i do the following:
1- Download this https://github.com/mb3364/Java-Twitch-Api-Wrapper and using it as a Lib.
2- Test this simple code to make sure im doing a good work:

Twitch twitch = new Twitch();
	URI callbackUri = null;
	try {
		callbackUri = new URI("");
	} catch (URISyntaxException e) {
	String authUrl = twitch.auth().getAuthenticationUrl(twitch.getClientId(), callbackUri, Scopes.USER_READ);
	try {
		String url = authUrl + "&force_verify=true";
	} catch (java.io.IOException e) {
	boolean authSuccess = twitch.auth().awaitAccessToken();
	if (authSuccess) {
		  String accessToken = twitch.auth().getAccessToken();
		  System.out.println("Access Token: " + accessToken);
	} else {

But the problem is that i never reach that final If because is always waiting.
Any help will be welcome.

Thanks for the help.

At what point is it getting stuck? Your Java app should open a browser window pointing to Twitch. You should permit the app access, which redirects you back to the app’s callbackUri, which tells the app the it’s found the token and the authorization should be successful.

If you never get a browser window, then your code is breaking when it tries to open a browser. If it never gets past authorizing the app with Twitch (ie you’re redirected back and nothing happens), java.awt.Desktop.getDesktop().browse may be a blocking call that you need to initiate in a separate thread.

The function twitch.auth().awaitAccessToken(); never ends, it keeps waiting, but never returns true or false even when i can see the token access in the browser. Can it be because of my Redirect URI? I have “” but i dont know if is a good practice or not.

Ok, i´ve solved it, i will post here the solution for any1 who got the same misstake if you are using Api-Twitch-Wrapper( https://github.com/mb3364/Java-Twitch-Api-Wrapper ):

1- Change your Redirect Uri in you Twitch account to:
2- Go to your project and change the callbackUri variable to the same string:

Thats all, it was a simple error, but it consumed some time until i realised it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.