views:

599

answers:

2

Android: I am trying the following xAuth example for android share.

http://stackoverflow.com/questions/3280328/xauth-authentication-for-twitter-share-in-android

System.setProperty("twitter4j.oauth.consumerKey", "your token");
System.setProperty("twitter4j.oauth.consumerSecret", "your token secret");

Twitter twitter = new TwitterFactory().getInstance(login, password);

AccessToken accessToken = twitter.getOAuthAccessToken();
//Then you must save your Token and Token secret from AccesToken

if (mAccessToken != null) {
    if (mAccessToken.getToken() != null && mAccessToken.getTokenSecret() != null) {
        saveAccessToken(mAccessToken.getToken(), mAccessToken.getTokenSecret());
    }
}

I am having Illegalstate exception

Exception Msg: java.lang.IllegalStateException: OAuth consumer key/secret combination not supplied

at following line

AccessToken accessToken = twitter.getOAuthAccessToken();

I made changes some thing like following

Twitter twitter = new TwitterFactory().getInstance("login", "pass");
            twitter.setOAuthConsumer(getString(R.string.twtAPIKey), getString(R.string.twtSecret));
            AccessToken mAccessToken = twitter.getOAuthAccessToken();

and again i got exception Exception Msg: java.lang.IllegalStateException: Basic authenticated instance.

Any working example of xAuth ?

+1  A: 

I ' ve used following

ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(Consumer__Key); configurationBuilder.setOAuthConsumerSecret(Consumer_Secret); Configuration configuration = configurationBuilder.build(); Twitter twitter = new TwitterFactory(configuration).getInstance("username","password"); AccessToken token = twitter.getOAuthAccessToken(); System.out.println("Access Token " +token ); String name = token.getScreenName(); System.out.println("Screen Name" +name); PrintWriter out= response.getWriter(); out.println(token);

And successfully login to Twitter using Android app using xauth

success_anil
I tried above code it is giving following exception messageThe screen name / password combination seems to be invalid.
Faisal khan
This worked for me. Very useful bit of code for anyone who doesn't have time to learn XAuth/OAuth properly.
Reuben Scratton
@Faisal Khan Hi Have you got your keys enable for xAuth from Twitte. Probably this could be the reason for the error.
success_anil
Yes we are have to request twitter guys to have special xauth account and keys.
Faisal khan
A: 

same for my app

sheralam