如何从保存在Android上的帐户检索的Facebook-的authToken [英] How to retrieve an Facebook-AuthToken from the accounts saved on Android

查看:219
本文介绍了如何从保存在Android上的帐户检索的Facebook-的authToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要检索的authToken为Facebook(保存的 Facebook的Andr​​oid版)使用下面这段code。

I'm trying to retrieve the AuthToken for Facebook (saved by Facebook for Android) by using the following piece of code.

AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.facebook.auth.login");
if (accounts.length > 0) {          
    for(int j = 0; j < accounts.length; j++) {
        Account account = accounts[j];
        if(account.type != null && account.type.equals("com.facebook.auth.login")) { 
            Log.e(RuntimeVars.MY_NAME, "FACEBOOK-TYPE FOUND");
            am.getAuthToken(account, "com.facebook.auth.login", null, ConversationList.this,
                new AccountManagerCallback<Bundle>() {
                    public void run(AccountManagerFuture<Bundle> arg0) {
                        try {
                            Bundle b = arg0.getResult();
                            Log.e(RuntimeVars.MY_NAME, "THIS AUTHTOKEN: " + b.getString(AccountManager.KEY_AUTHTOKEN));
                        }
                        catch (Exception e) {
                            Log.e(RuntimeVars.MY_NAME, "EXCEPTION@AUTHTOKEN");
                        }
                    }
                }, null);
            }
        }
    }

登录凭据发现的 Facebook的类型中找到的写入LogCat中,但也的此的authToken:[...] 的也不异常@的authToken 的记录。所以我想 am.getAuthToken 永远不会被调用。

The login credentials are found and FACEBOOK-TYPE FOUND is written into LogCat, but neither THIS AUTHTOKEN: [...] nor EXCEPTION@AUTHTOKEN is logged. So I suppose am.getAuthToken is never called.

我在想什么?

在一般情况下,如果有一个更好的(至少工作)的方法来检索从Android Facebook的账户的authToken请让我知道。

In general, if there is a better (and at least working) approach to retrieve the Facebook authtoken from the Android accounts please let me know.

非常感谢您的帮助!

最好的问候
秒。

Best regards
S.

推荐答案

为什么不使用Facebook SDK?

Why not use the Facebook SDK?

的Facebook 类中有一个成员获得的OAuth 2.0访问令牌(如果这是你所需要的), getAccessToken()

The Facebook class in it has a member to get the OAuth 2.0 access token (if that is what you need), getAccessToken().

这篇关于如何从保存在Android上的帐户检索的Facebook-的authToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆