【问题标题】:Using HtmlUnit to get the access token from instagram使用 HtmlUnit 从 instagram 获取访问令牌
【发布时间】:2015-09-25 18:08:21
【问题描述】:

由于 httpURLconnection 没有切断,我切换到 htmlUnit 以编程方式获取身份验证代码以从 instagram 获取访问令牌,然后从那里执行我需要的任何操作,问题是我一直在尝试检索授权代码从网址

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

这是我尝试访问该网址的代码:

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());

【问题讨论】:

标签: java instagram htmlunit htmlunit-driver


【解决方案1】:

我通过尝试在不登录网站的情况下获取授权 url 解决了这个问题,然后当我被要求登录时,我使用了htmlunit to get the html form to login to instagram,最后我可以通过代码获得所需的重定向 url。

【讨论】:

    猜你喜欢
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    相关资源
    最近更新 更多