【问题标题】:Vaadin with Instagram APIVaadin 与 Instagram API
【发布时间】:2014-07-05 11:03:10
【问题描述】:

要使用我的应用,用户必须登录他们的 Instagram 帐户并授予我的应用访问他们信息的权限。

完成后,将返回一个附有代码的 URL(例如 www.google.com/code=123456789)。

代码用于交换访问令牌。

我的问题是:

我的应用能否自动从 url 获取代码并使用它,而不是用户必须复制和粘贴它?

感谢您的阅读!

代码:

TextField code = new TextField("Enter Code: ");

Button button = new Button("Click here to authenticate");

String callbackUrl = "http://reveal-it.appspot.com/oauthtest";

String clientID = "XXX";

String clientSecret = "XXX";

Token EMPTY_TOKEN = null;

InstagramService service = new 
InstagramAuthService().apiKey(clientId)
                      .apiSecret(clientSecret)
                      .callback(callbackUrl)
                      .build();

String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);



button.addClickListener(new Button.ClickListener() {

    public void buttonClick(ClickEvent event) {
        getUI().getPage().open(authorizationUrl, "_blank");
        next();
    }   
});

public void next(){

    String verifierCode = code.getValue();

    Verifier verifier = new Verifier(verifierCode);

    Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);

    Instagram instagram = new Instagram(accessToken);

    UserInfo userInfo = instagram.getCurrentUserInfo();    

}

第 1 步:验证用户身份

第 2 步:获取 URL,后面附有代码,用户必须复制并粘贴到文本字段中 (这是打印代码的测试网址)

【问题讨论】:

  • 您不知道如何自动获取令牌访问权限?我也在使用 jinstagram,而不是每次我尝试使用 HttpURLConnection 访问 url 时都复制粘贴 authorizationUrl 但它不会返回像 www.mysite.com/instagram/oauth?code=ACCESS_TOKEN 这样的东西

标签: java vaadin instagram


【解决方案1】:

这些社交平台通常使用 oauth 进行登录和权限授予。 对此有一个 vaadin 插件。

https://vaadin.com/directory#addon/oauth-popup-add-on

【讨论】:

  • 我收到“抱歉,找不到请求的插件。”当我点击那个链接时。
  • 抱歉,已更正链接,不需要 https。如果还是不行,就搜索插件:OAuth Popup Add-on
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-01
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 2022-06-19
相关资源
最近更新 更多