Android access token problem

sanehussain
@sanehussain Syed Rameez Hussain

I am developing an android app where a user can use their twitter account to post tweets via the app. I've tried posting tweets using the app key and secret (obtained by using the button "create access token" on my app page), hardcoded it in my app and it worked. But when I try to make my app redirect for user authentication, it gives me an error saying "illegalargumentexception: invalid values for access token pair." My code looks like this:

public class TwitterUtils {

public static boolean isAuthenticated(SharedPreferences prefs) {

AccessToken a = null;

String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

a = new AccessToken(token,secret);

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(TwitterConstants.CONSUMER_KEY, TwitterConstants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);

try {
twitter.verifyCredentials();
return true;
} catch (TwitterException e) {
return false;
}
}

public static void sendTweet(SharedPreferences prefs,String msg) throws Exception {
String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

AccessToken a = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(TwitterConstants.CONSUMER_KEY, TwitterConstants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
twitter.updateStatus(msg);
}

}

I've taken this from a tutorial. Can anyone tell me what's wrong?

1 year 28 weeks ago

Replies

FekuSalim
@FekuSalim Salim Feku

is this possible if we want to login from twitter app in our android application?if yes then how we can?

40 weeks 18 hours ago