2014-07-05 58 views
0

要使用我的應用程序,用戶必須登錄到他們的Instagram帳戶,並授予我的應用程序訪問其信息的權限。Vaadin with Instagram API

完成此操作後,會返回一個代碼附在後面的網址(例如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:驗證用戶 enter image description here

步驟2:獲取URL與連接在該用戶具有複製並粘貼到文本字段 (這是一個測試背面代碼打印代碼的網址) enter image description here

+0

你不知道如何自動獲得訪問令牌?即時通訊也使用jinstagram太多,而不是copypasting _authorizationUrl_每次我試圖訪問URL與HttpURLConnection但它不會像'www.mysite.com/instagram/oauth?代碼= ACCESS_TOKEN'返回something「 –

回答

0

這些社交平臺通常使用oauth進行登錄和授權。 這裏有一個vaadin插件。

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

+0

我得到」對不起,請求添加 - 無法找到。「當我點擊那個鏈接。 – user3702643

+0

對不起,更正了鏈接,沒有https需要。 如果仍然無法正常工作,請搜索插件: OAuth彈出式附加組件 –