2011-10-10 92 views
1

我建立使用Oauth1.0 Android上的Twitter客戶端,我在中間Twitter客戶端的Oauth Athentication爲Android

super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    OAuthConsumer consumer = new DefaultOAuthConsumer(
      "CONSUMER_KEY", 
      "CONSUMER_CUSTOMER_KEY"); 

    OAuthProvider provider = new DefaultOAuthProvider(
      "https://api.twitter.com/oauth/request_token", 
      "https://api.twitter.com/oauth/access_token", 
      "https://api.twitter.com/oauth/authorize"); 

    Toast.makeText(getApplicationContext(), "fetching request token", Toast.LENGTH_SHORT).show(); 
    try 
    { 
     String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND); 
    // Toast.makeText(getApplicationContext(), authUrl, Toast.LENGTH_SHORT).show(); 

     String url = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND); 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND); 
     this.startActivity(intent); 


    } 


    catch (OAuthMessageSignerException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    catch (OAuthNotAuthorizedException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    catch (OAuthExpectationFailedException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    catch (OAuthCommunicationException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 



} 

現在我已經能與此授權的地方卡住了,但只要我輸入我的用戶名和密碼,出現PIN碼,不發生重定向!那麼我想要的是顯示用戶的推文,而無需輸入PIN碼!我該怎麼辦 ?

由於提前

回答

1

第一步是讀取OOB權威性的文件上dev.twitter.com

對於確實無法處理全過程的OAuth應用 的Twitter提供了帶外/ PIN碼身份驗證模式,也稱爲oob的 。

此驗證流程與完整OAuth幾乎完全相同,只有 而不是導回到您的網站,用戶出示 與PIN碼。

您需要引導用戶到您的應用程序輸入提供的PIN碼以完成auth過程。如果您想重定向,請將完整的oAuth1.0a流程與服務器組件一起使用,或者將回調URL作爲鏈接打開您的Android應用程序。

+0

實際上回調網址的位置在哪裏,以及究竟應該放入哪個網址! B'coz從用戶的角度看,沒有人會將密碼輸入到應用程序中 – Anuj

+0

我該如何將URL傳遞迴我的應用程序? – Anuj

+0

請參閱[oAuth流](https://dev.twitter.com/docs/auth/oauth)使用回調URL和[此問題](http://stackoverflow.com/questions/2958701/launch-custom- android-application-from-android-browser)從瀏覽器中啓動一個應用程序 – markdsievers