如何在twitter中使用android AccountManager进行授权?

时间:2012-08-17 01:45:13

标签: android twitter accountmanager scribe android-account

如何使用Android AccountManager在Twitter中进行授权?

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

现在我得到了 com.twitter.android.oauth.token com.twitter.android.oauth.token.secret 。但下一步是什么?我如何使用它来授权?

我使用scribe api,我试图像这样使用它:

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

但它不起作用。我还尝试了另一种不起作用的方法。 有很多这样的问题:

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

没有人给出具体答案

1 个答案:

答案 0 :(得分:1)

Android的AccountManager返回的com.twitter.android.oauth.tokencom.twitter.android.oauth.token.secret凭据仅使用Twitter的官方消费者密钥和密钥进行身份验证。 AFAIK它们实际上对第三方开发人员没用。

对于Twitter,我只是说他们在那里,如果Twitter通过应用更新改变了他们,他们就会为没有该应用更新的每个用户打破OAuth。