6

I have an issue as said in the title of this post. I am unable to login.

SessionState currentstate =  session.getState();

gives me a state CLOSED_LOGIN_FAILED. I took a look at this post, Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in

I generated a key using the keytool and put that in the App Dashboard. But that does not seem to help. Any help on this appreciated

Community
  • 1
  • 1
perceptron
  • 167
  • 2
  • 13
  • the actuall reason behind this is the corrupt openssl,please download openssl from http://gnuwin32.sourceforge.net/packages/openssl.htm and your problem will be gone – Muhammad Babar Apr 25 '13 at 10:52

2 Answers2

31

call this below method from oncreate of your activity , it will print a hash key in logcat, add that into hash field in app setting on Facebook. try again it will work

  public void printHashKey() {

        try {
            PackageInfo info = getPackageManager().getPackageInfo("your.package.name",
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("TEMPTAGHASH KEY:",
                        Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

    }
AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • 1
    I did this and the key that is printed out is different now ? I have put this new key now. How long does it take to reflect on the server ? – perceptron Jan 23 '13 at 18:22
  • not much time, try it now. make sure you have added it at a right place though :) – AAnkit Jan 23 '13 at 18:31
  • have u changed package name in this line getPackageInfo("your.package.name"). actually u need to add ur package name here. make sure u did it, else hash key ll be different. – AAnkit Jan 23 '13 at 18:33
  • Thanks. Yep, I put in my package name. And the hash key printed out is what I used. Should the "Package Name" and "Class Name" fields on the dashboard be populated as well. – perceptron Jan 23 '13 at 18:35
  • Print the exception in logincallBack , on complete method , and let me know what it says – AAnkit Jan 23 '13 at 19:03
  • 2
    I do not get any exception, in callback method. However, I notice that the status is always CLOSED_LOGIN_FAILED – perceptron Jan 23 '13 at 19:29
  • There is Exception parameter with Status. print status and Exception both, if it is failed, there must be an Exception too. – AAnkit Jan 23 '13 at 19:36
  • Here is what happens, when I try to create a new session, it identifies my app correctly based on the App_id, and it says "Your app wants to access...." through a dialog. When I hit OK, the callback method is called and the session.getstate() returns OPENING. And there is nothing in the logcat. Earlier when the state used to be CLOSED_LOGIN_FAILED, there were exception as I have told in my post. – perceptron Jan 23 '13 at 19:50
  • and it is not getting opening? it takes some time to return back to on complete? are you following "getting stareted " guide of FB for android? is it perfect – AAnkit Jan 23 '13 at 19:52
  • Finally it works !!!! The issue was probably with the HASH KEY. I copied the HASH KEY. Removed the package name and class name. That did it. – perceptron Jan 23 '13 at 20:08
  • Good to hear this. :) happy coding :) – AAnkit Jan 24 '13 at 06:29
  • After several attempts it ended up working. Keep trying. Similar post and answer here http://stackoverflow.com/questions/15002701/sessionstate-is-closed-login-failed-in-fb-native-login – daffycricket Mar 25 '13 at 23:45
  • I generated a hash key from console and i tried this code .They are diffent why? What is this meaning? And this code worked but generated hash key is not working in my app.Can anybody tell me difference? What is right both of them? – DuyguK Jan 07 '14 at 21:00
  • this means you are generating HASH key but using different key to sign your apk. – AAnkit Jan 08 '14 at 12:39
  • If anyone needs the imports for this script: `import android.content.*; import android.content.pm.*; import android.content.pm.PackageManager.*; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import android.util.Base64; ` – Sebastian Jul 23 '14 at 10:40
  • This piece of code gives me a different HASHKEY and the method to generate the hash key using this line of code ( keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 ) gives me a different hash key. – Sagar Devanga Jul 06 '15 at 10:43
5

I know this has already has a selected answer, but it is important to note that if you are trying to use keytool instead of printing the keyhash in code, make sure you use the keytool that comes with java 1.6 instead of java 1.7.

natez0r
  • 1,064
  • 9
  • 14