2012-08-17 37 views
4

如何在twitter中使用android AccountManager授權?如何使用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", "[email protected]"); 
       } 
    }}, null); 
} 

現在,我得到com.twitter.android.oauth.tokencom.twitter.android.oauth.token.secret。但下一步是什麼?我如何使用它來授權?

我用隸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

,沒有人給出具體的答案

+0

你能更具體嗎?什麼不行?你有錯誤嗎?什麼是堆棧跟蹤?你在調試模式下用'scribe'試過了嗎?你給出的代碼示例中'token'和'secret'的值是多少? – 2012-08-17 18:34:46

+0

我不建議你前進你的應用程序(對不起),因爲twitter限制了它的訪問。閱讀本文:Twitter想阻止你使用Twitter推出的Twitter應用程序http://gizmodo.com/5935517 – 2012-08-17 02:11:43

+0

其實我只需要用戶個人資料數據.. – pleerock 2012-08-17 02:15:08

回答

1

通過Android的的AccountManager只返回使用Twitter官方的使用者密鑰和機密身份驗證的com.twitter.android.oauth.token和​​憑據。 AFAIK它們對第三方開發人員實際上並不有用。

對於Twitter,我只是說他們在那裏,如果Twitter通過應用更新改變他們,他們會在沒有該應用更新的情況下爲每個用戶分配OAuth。

+0

確認:http://stackoverflow.com/a/19832978/188926 – Dunc 2014-07-09 10:20:58