Twitter client Oauth Athentication for Android

907 views Asked by At

I am building a Twitter client for android using Oauth1.0 and i am stuck somewhere in the middle

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



}

Now i have been able to authorize with this , but as soon as i enter my username and password , A pin code appears and no redirection takes place ! Well what i want is to display tweets of the user without entering the Pin Code ! What should i do ?

Thanks in Advance

1

There are 1 answers

5
markdsievers On BEST ANSWER

First step is to read the documentation on OOB auth on dev.twitter.com

For applications that really can't handle the full OAuth process Twitter provides the out-of-band/PIN code authentication mode, also known as oob.

This authentication flow is almost identical to full OAuth except instead of being directed back to your website the user is presented with a PIN code.

You need to direct the user to your application to enter the supplied PIN code to complete the auth process. If you want redirection, use the full oAuth1.0a flow with either a server component, or make the callback URL a link to open your android application.