2011-10-10 70 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