How to authorize in twitter using android AccountManager?

1.6k Views Asked by At

How to authorize in twitter using android AccountManager?

AccountManager am = AccountManager.get(this);
Account[] accts = am.getAccountsByType(TWITTER_ACCOUNT_TYPE);
if(accts.length > 0) {
    Account acct = accts[0];
    am.getAuthToken(acct, "com.twitter.android.oauth.token"/*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);
}

Now I got com.twitter.android.oauth.token and com.twitter.android.oauth.token.secret . But what is the next step? How do I use this to authorize?

I use scribe api and I tried to use it like this:

service.signRequest(new Token(token, secret), request);

But it doesn't work. Ive also tried another methods which don't work. There are a lot of questions like this:

https://dev.twitter.com/discussions/4875

https://groups.google.com/forum/?fromgroups#!topic/twitter-development-talk/1tWEx--5h9w%5B1-25%5D

http://osdir.com/ml/twitter4j/2011-06/msg00128.html

Android: How to Twitter oAuth Through Account Manager

Twitter Authentication through Android's AccountManager classes

Using account manager to get OAuth token

and no one gives concrete answer

1

There are 1 best solutions below

0
On

The com.twitter.android.oauth.token and com.twitter.android.oauth.token.secret credentials returned by Android's AccountManager only authenticate using Twitter's official Consumer Key and Secret. AFAIK They're not actually useful to third party developers.

With respect to Twitter I'll just say they're out there, and if Twitter changed them via an app update they'd break OAuth for every user without that app update.