Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Authentication through Android's AccountManager classes

I am working on a twitter based app and am trying to incorporate Android's built-in Account support for Twitter. The following code works to popup the confirmation dialog for my app to access twitter but I am unsure of what to pass in as the authenticationType. Any help would be appreciated. I've googled all over the place and can't seem to find the correct answer. It goes in place of "oauth" below.

AccountManager am = AccountManager.get(this);
Account[] accts = am.getAccountsByType(TWITTER_ACCOUNT_TYPE);
if(accts.length > 0) {
    Account acct = accts[0];
    am.getAuthToken(acct, "oauth"/*what goes here*/, null, this, new AccountManagerCallback<Bundle>() {

    @Override
    public void run(AccountManagerFuture<Bundle> arg0) {
        try {
                     Bundle b = arg0.getResult();  
                     Log.e("TrendDroid", "THIS AUTHTOKEN: " + b.getString(AccountManager.KEY_AUTHTOKEN));  
                } catch (Exception e) {  
                     Log.e("TrendDroid", "EXCEPTION@AUTHTOKEN");  
                }  
    }}, null);
}
like image 639
Robby Pond Avatar asked Feb 01 '11 22:02

Robby Pond


1 Answers

If you want OAuth you should use those ones :

  • com.twitter.android.oauth.token
  • com.twitter.android.oauth.token.secret

If you want the user's password then you can write your own authenticator. The official Twitter application does not store the password. The password is used only once to get those two tokens.

like image 158
A. Fournier Avatar answered Nov 15 '22 18:11

A. Fournier