Facebook Android SDK 登录后不打开 Session [英] Facebook Android SDK does not open Session after login

查看:14
本文介绍了Facebook Android SDK 登录后不打开 Session的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)这个问题出现了很多次,并且 awnser 总是你有错误的 Key Hash".

1) This question appears many times and the awnser is always "you have the wrong Key Hash".

2) Facebook 文档告诉我们使用此代码来获取我们的密钥哈希:

2) Facebook documentation tells we to use this code to get our Key Hash:

keytool -exportcert -alias MyKeyAlias -keystore path	omyKey | openssl sha1 -binary | openssl base64

3) 好的,这给了我那个键:1yl**********Q3A

3) Ok, this gives me that key: 1yl**********Q3A

当我尝试登录时,我收到以下消息:com.facebook.http.protocol.ApiException: (#404) 密钥哈希 XHA**********q10 与任何存储的密钥哈希不匹配.

When I try to login, I got the following message: com.facebook.http.protocol.ApiException: (#404) Key hash XHA**********q10 does not match any stored key hashes.

4) 然后我将 XHA**********q10 复制并粘贴到我的应用设置中,这也不是我的密钥.

4) Then I copy and paste the XHA**********q10 on my app settings and thats not my key either.

5) 因此,我阅读了文档,该文档是为您提供正确密钥哈希的代码.这段代码:

5) So, I read on documentation that was a code that gives you the correct Key Hash. This code:

// Add code to print out the key hash
try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "com.facebook.samples.hellofacebook", 
            PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

成功了!给我这个哈希:+HA**********q0=

It worked! Gave me this hash: +HA**********q0=

6) 我将最后一个哈希值放在应用设置上,是的,现在我可以连接了!但是,现在我无法打开会话!!!

6) I put this last hash on app settings and YES, now I can connect! BUT, now I can't open a Session!!!

我正在使用以下代码:

public class FBActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_view);

        System.out.println("Start Facebook login");
        Session.openActiveSession(this, true, new Session.StatusCallback() {
            public void call(Session session, SessionState state, 
                                              Exception exception) {
                System.out.println("Call");
                if (session.isOpened()) {
                    System.out.println("Open");
                    Request.newMeRequest(session, new Request.GraphUserCallback() {
                        public void onCompleted(GraphUser user, Response response) {
                            System.out.println("Complete");
                            if (user != null) {
                                System.out.println(user.getName());

                            } else {
                                System.out.println("User NULL");
                            }
                        }
                    }).executeAsync();
                } else {
                System.out.println("Not open");
            }

        });
    }
}

日志是:

开始 Facebook 登录

"Start Facebook Login

打电话

未打开

打电话

未打开"

我不知道还能做什么,因为我已经有了正确的 Key Hash 并且可以登录.

I don't know what else can I do, since I already have the correct Key Hash and I can make the login.

推荐答案

我想通了:

缺少以下方法.刚刚添加它,一切正常.

The following method was missing. Just added it and everything worked.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

这篇关于Facebook Android SDK 登录后不打开 Session的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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