微博认证通过Android的的AccountManager类Android、AccountManager

2023-09-05 07:24:55 作者:银河上映中

我工作的一个基于Twitter的应用程序,我试图将Android的内置的Twitter帐户的支持。下面code工程,以弹出我的应用程序的确认对话框来访问Twitter,但我不确定该怎么传递的authenticationType。任何帮助将是AP preciated。我GOOGLE了所有的地方,似乎无法找到正确的答案。它去的地方OAuth的下面。

 的AccountManager AM = AccountManager.get(本);
帐户[] accts = am.getAccountsByType(TWITTER_ACCOUNT_TYPE);
如果(accts.length大于0){
    帐户的acct = accts [0];
    am.getAuthToken(科目,OAuth的/ *发生的事情在这里* /,空,为此,新AccountManagerCallback<包>(){

    @覆盖
    公共无效的run(AccountManagerFuture<包>为arg0){
        尝试 {
                     叠B = arg0.getResult();
                     Log.e(TrendDroid,这的authToken:+ b.getString(AccountManager.KEY_AUTHTOKEN));
                }赶上(例外五){
                     Log.e(TrendDroid,异常@的authToken);
                }
    }}, 空值);
}
 

解决方案

如果你想OAuth的,你应该使用这些的:

com.twitter.android.oauth.token com.twitter.android.oauth.token.secret 如何在Android中移除帐户中的AccountManager

如果您希望用户的密码,那么你可以编写自己的身份验证。在官方Twitter应用程序不存储密码。密码只能使用一次拿到这两个标记。

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

解决方案

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.