由于httpURLconnection没有删除,我切换到htmlUnit以编程方式获取auth代码以从instagram获取访问令牌,然后从那里做我需要的任何东西,事情是我被困在尝试从URL检索授权代码
mysite.com/?code=ca1ec5b06a0b409293cff74ed9876a46
但我无法访问该链接,因为它似乎没有从授权URL重定向 . 这个:
https://instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id%CLIENT_ID%26redirect_uri%3Dhttp%3A//MYSITE.COM%26response_type%3Dcode
这是我尝试访问该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());
1 回答
我通过尝试获取授权URL而没有登录到网站来解决这个问题,然后当我被要求登录时,我使用htmlunit to get the html form to login to instagram,最后我可以使用代码获得所需的重定向URL .