简体   繁体   English

Android - 打开会话不能使用上一个Facebook应用程序版本,如果未安装facebook,则工作正常

[英]Android - Open session not working with last Facebook app version and working fine if facebook not installed

i develop facebook application but when it installed to device it works fine if there is no facebook application installed on the device and when the facebook application installed the Session can not be open. 我开发Facebook应用程序但是当它安装到设备时,如果设备上没有安装facebook应用程序,并且安装了Session的facebook应用程序无法打开,它可以正常工作。 My code as below, 我的代码如下,

Session.openActiveSession(this, true,
            new Session.StatusCallback() {
                // callback when session changes state
                @Override
                public void call(Session session, SessionState   state,
                        Exception exception) {
                    if (session.isOpened()) {

                        // make request to the /me API
                        Request.executeMeRequestAsync(session,
                                new Request.GraphUserCallback() {
                                    @Override
                                    public void onCompleted(GraphUser user,
                                            Response res) {
                                        if (user != null) {
                                            User.getInstance().setProfile(user);

                                        }
                                    }
                                });
                    }
                }
            });

      @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode,  data);
      if(Session.getActiveSession().isOpened()) {
          Log.i("here opened", "thnx");

      }
}

hy guys i want to share this info with you for any one face the above problem. hy伙伴们,我想与你分享这些信息,任何人都面临上述问题。

Some times when you developing facebook application you will need to generate the hash key by keytool "you can generate it by this command keytool -exportcert -alias androiddebugkey -keystore C:\\Users\\YOURUSER.android\\debug.keystore | "C:\\bin\\bin\\openssl" sha1 -binary |"C:\\bin\\bin\\openssl" base64 the enter android as a password ". 有时当你开发facebook应用程序时,你需要通过keytool生成散列键“你可以通过这个命令生成它keytool -exportcert -alias androiddebugkey -keystore C:\\ Users \\ YOURUSER.android \\ debug.keystore |”C:\\ bin \\ bin \\ openssl“sha1 -binary |”C:\\ bin \\ bin \\ openssl“base64输入android作为密码”。

The problem in above method it sometimes generate wrong hash key as it depends on the JDK version and used openssl application so your facebook application can not be logged in. 上述方法中的问题有时会产生错误的哈希键,因为它取决于JDK版本并使用openssl应用程序,因此您的Facebook应用程序无法登录。

The problem solve you can write below code in your activity and use the generated hash key instead above one and every thing will be working fine. 问题解决了你可以在你的活动中写下面的代码,并使用生成的哈希键代替上面的一个,每个东西都可以正常工作。

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.kartag.gui", 
                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) {

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM