Twitter Authentication through Android's AccountManager classes

泄露秘密 提交于 2019-12-18 11:34:02

问题


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

回答1:


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.




回答2:


from AccountManager docs:

Some authenticators have auth token types, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.

I think, it is not very important. You should really ask the developer of twitter authenticator. Or write your own.



来源:https://stackoverflow.com/questions/4868770/twitter-authentication-through-androids-accountmanager-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!