4

I was trying to get the key hash from my Android app. Facebook SDK 3.0 gave the following code:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

When I run this it first says binary:no error; It then asks for the password which I enter as android. Upon pressing enter it returns blank where I expect the pass code.

I used the solution mentioned here; this did give me a key hash but when I use that none of the sessions are opening.

My java keytool is stored in :

C:\Program Files\Java\jre7\bin

And OpenSSL is stored in :

F:\openssl\bin

I am giving the correct file paths when I run it in MD in Windows.

Kindly help me figure this out!

Community
  • 1
  • 1
thenoob
  • 63
  • 6
  • Also another one here: http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash?rq=1 – Stephen C May 31 '14 at 23:06

2 Answers2

0

Windows is always a little hairy and tricky to get the keytool, I suggest the alternative. Run the following code in the onCreate method of your app:

   try {
        PackageInfo info = getPackageManager().getPackageInfo(
            "COM.YOUR.PACKAGE.NAME", 
            PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("My Keyhash", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (Exception e) {
        Log.e("My Keyhash", e.toString());
    } 

and observe the log output in logcat to obtain your keyhash. Make sure to replace the package name above with your own.

EDIT:

the key hash is correctly uploaded but the session still does not open... while logging on to facebook it first requests for my permission throgh the app and the after i accept a popup come up saying "com.facebook.facebookexception: Session Provided to a request in unopened state"

Make sure you have this code in your Fragment/Activity:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}
Jesse Chen
  • 4,928
  • 1
  • 20
  • 20
  • thanks .. the key hash got generated but i updated my app but the session still dosen't work. – thenoob Jan 02 '13 at 19:01
  • you're going to have to provide more detail than that if you want help (e.g. stack trace, error messages) – Jesse Chen Jan 02 '13 at 19:05
  • the key hash is correctly uploaded but the session still does not open... while logging on to facebook it first requests for my permission throgh the app and the after i accept a popup come up saying "com.facebook.facebookexception: Session Provided to a request in unopened state" – thenoob Jan 03 '13 at 18:52
  • 2
    yes a version of that code is present... the issue is that even sample apps given in the facebook 3.0 SDk are not working and give the above error – thenoob Jan 03 '13 at 20:06
  • I would try removing the app from your authorized apps in your FB settings and then re-authing the app. Apart from that, it sounds like there is a configuration issue with your app because I have not heard reports of the sample apps having this problem and I am unable to repro either. – Jesse Chen Jan 03 '13 at 20:43
  • i am also getting the same above issue,how to reslove please help? – Nilesh Verma Feb 05 '13 at 12:14
0

You might got the password wrong.

Look at my answer Here.

Hope that helps

Community
  • 1
  • 1
Shahar
  • 3,692
  • 4
  • 25
  • 47