Since httpURLconnection didn't cut out, i switched to htmlUnit to get programatically the auth code to get the access token from instagram and then do whatever i need from there, the thing is i'm stuck trying to retrieve the authorization code from the url
mysite.com/?code=ca1ec5b06a0b409293cff74ed9876a46
but i can't access to that link since it doesn't seems to be redirected from the authorization URL. this one:
this is my code where i try to access to that url:
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(true);
HtmlPage page = (HtmlPage) webClient.getPage(authURL);
WebResponse response = page.getWebResponse();
String content = response.getContentAsString();
System.out.println(page.getUrl());
I resolved this by trying to get the authorization url without being logged to the site, then when i was asked to login, i used htmlunit to get the html form to login to instagram, finally i could get the desired redirect url with the code.