Key hash for Android-Facebook app

后端 未结 30 3168
误落风尘
误落风尘 2020-11-22 01:17

I\'m working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the readme.md (text file) in there,

30条回答
  •  Happy的楠姐
    2020-11-22 01:52

    There are two methods available complex one and the easy one

    Methods One :(little Complex)

    first of all you have to download ssl 64bit or 32bit accordingly, remember to download the file with name containing e after version code openssl-0.9.8e_X64.zip OR openssl-0.9.8e_WIN32.zip not with the k after the version code,

    and place in AndroidStudio/jre/bin directory, if you dont know where to place, you can find this directory by right clicking on the android studio shortcut as:

    now you have managed two required things in one place, but still you have to find the path for your debug.keystore, that is always can be found in the "C:\Users\yourusernamehere\.android\debug.keystore",

    NOTE If your app is published already, or about to publish then use your publishing signing keystore, if and only if your are testing in development mode than you can use debug,keysotre

    As everything is setup, let arrange the command you wanted to execute for the hash key generation in base64 format, and you command will look like this

    keytool.exe -exportcert -alias androiddebugkey -keystore "C:\Users\ayyaz talat\.android\debug.keystore" | "D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" sha1 -binary |"D:\Program Files\Android\Android Studio\jre\bin\openssl\bin\openssl.exe" base64
    

    it will promt you to enter a password for the debug.keystore, which is android by default. if you are using your own key than the password will be also yours. the output will look like this if everything goes well as expected, hope it may help

    Second Method (Respectively easy one)

    if you dont want to go throught all the above procedure, then just use the following method to log the haskey:

     private void printKeyHash() {
            try {
                PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA1");
                    md.update(signature.toByteArray());
                    Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
            } catch (PackageManager.NameNotFoundException e) {
                Log.e("KeyHash:", e.toString());
            } catch (NoSuchAlgorithmException e) {
                Log.e("KeyHash:", e.toString());
            }
        }
    

    output:

提交回复
热议问题