Key hash for Android-Facebook app

2018-12-31 03:43发布

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, in which it is mentioned to generate the key hash for Android. How do I generate it?

29条回答
长期被迫恋爱
2楼-- · 2018-12-31 04:13

For Windows:-

1.Download openssl(openssl-for-windows)
2.Copy and Paste openssl folder into c drive.
3.C:\Android\.android\debug.keystore => Debug Keystore path
4.C:\Program Files\Java\jdk1.8.0_181 => JDK PATH
5.Go to jdkpath=>Enter the below command. (keytool inside Debug keystore path)  

keytool -exportcert -alias androiddebugkey -keystore C:\Android.android \debug.keystore |"C:\openSSL\bin\openssl" sha1 -binary | "C:\openSSL\bin \openssl" base64

查看更多
浅入江南
3楼-- · 2018-12-31 04:14

To generate a hash of your release key, run the following command on Mac or Windows substituting your release key alias and the path to your keystore.

On Windows, use:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

This command should generate a 28 characher string. Remember that COPY and PASTE this Release Key Hash into your Facebook App ID's Android settings.

image: fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2178-6/851568_627654437290708_1803108402_n.png

Refer from : https://developers.facebook.com/docs/android/getting-started#release-key-hash and http://note.taable.com

查看更多
有味是清欢
4楼-- · 2018-12-31 04:14

For people who dont know how to code, AivarsDa's key gen tool on google play i the easiest solution. just get the hash key from it and copy to the facebook app settings. The share on the keygen tool makes my app crash on my phone, so i just manually typed it in notepad and copied it to fb. Finally past this step after days of frustration

查看更多
ら面具成の殇う
5楼-- · 2018-12-31 04:16

Use this for print key hash in kotlin

try {
        val info = context.getPackageManager().getPackageInfo(context.packageName,
                PackageManager.GET_SIGNATURES);
        for (signature in info.signatures) {
            val md = MessageDigest.getInstance("SHA")
            md.update(signature.toByteArray())
            Log.d("Key hash ", android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT))
        }
    }catch (e:Exception){

    }
查看更多
其实,你不懂
6楼-- · 2018-12-31 04:17

I've created a small tool for Windows and Mac OS X. Just throw in the key-store file, and get the hash key.

If you want the default debug.keystore file, use the default alias and password. Else, use your own keystore file and values.

Check it out, download the Windows version or download the Mac OS X version (Dev-Host might be down sometimes... so if the link is broken, PM me and I'll fix it).

I hope that help you guys...

Dec 31, 2014 - EDIT: Changed host to AFH. Please let me know if the links are broken

Nov 21, 2013 - EDIT:

As users requested, I added a default keystore location and a DONATE button. Feel free to use it if I've helped you. :)

Screen shot Screen shot 2

查看更多
裙下三千臣
7楼-- · 2018-12-31 04:21

Add this code to onCreate of your activity, it will print the hash under the KeyHash tag in your logCat

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           getPackageName(),
                           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) {

}

You can add multiple hashkeys for your account, so if you been running in debug don't forget to run this again in release mode.

查看更多
登录 后发表回答