本文介绍了通过 Android 的 AccountManager 类进行 Twitter 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于 twitter 的应用程序,并正在尝试将 Android 内置的 Twitter 帐户支持纳入其中.以下代码用于为我的应用程序弹出确认对话框以访问 Twitter,但我不确定要作为 authenticationType 传递的内容.任何帮助,将不胜感激.我用谷歌搜索了很多地方,似乎找不到正确的答案.它代替下面的oauth".

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

推荐答案

如果你想要 OAuth 你应该使用那些:

If you want OAuth you should use those ones :

  • com.twitter.android.oauth.token
  • com.twitter.android.oauth.token.secret

如果您想要用户的密码,那么您可以编写自己的身份验证器.官方 Twitter 应用程序不存储密码.密码仅用于获取这两个令牌.

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.

这篇关于通过 Android 的 AccountManager 类进行 Twitter 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 20:29