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:28

The instructions currently in Facebook's Android Tutorial do not work well under Windows. Their example shows how to pipe the keytool output to openssl but if you try this under Windows the output is not valid for some reason. I found that I had to use intermediary files to get it to work properly. Here are the steps that worked for me:

Start by downloading openssl for Windows from Google.

C:\Users\Me>keytool -exportcert -alias my_key -keystore my.keystore -storepass PASSWORD > mycert.bin

C:\Users\Me>openssl sha1 -binary mycert.bin > sha1.bin

C:\Users\Me>openssl base64 -in sha1.bin -out base64.txt

After running these commands the valid hash is stored in the file base64.txt. Copy and paste this to your app settings on Facebook.

查看更多
还给你的自由
3楼-- · 2018-12-31 04:30

To get the Android key hash code, follow these steps:

  1. Download OpenSSL for Windows here
  2. Now unzip to the C drive
  3. Open a CMD prompt
  4. Type cd C:\Program Files\Java\jdk1.6.0_26\bin
  5. Then type only keytool -export -alias myAlias -keystore C:\Users\your user name\.android\myKeyStore | C:\openssl-0.9.8k_WIN32\bin\openssl sha1 -binary | C:\openssl-0.9.8k_WIN32\bin\openssl enc -a -e
  6. Done
查看更多
琉璃瓶的回忆
4楼-- · 2018-12-31 04:30

As answered on a similar issue i found this to be working for me:

  • Copy the apkname.apk file you want to know the hash of to the 'Java\jdk1.7.0_79\bin' folder
  • Run this command keytool -list -printcert -jarfile apkname.apk
  • Copy the SHA1 value and convert it using this site
  • Use the converted Keyhash value (ex. zaHqo1xcaPv6CmvlWnJk3SaNRIQ=)
查看更多
梦该遗忘
5楼-- · 2018-12-31 04:32

Here are the steps-

  1. Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)

  2. Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.

  3. detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step.

  4. detect your keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-

    $ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

    • it will ask for password, put android
    • that's all. u will get a key-hash

For more info visit here

查看更多
流年柔荑漫光年
6楼-- · 2018-12-31 04:33

The simplest solution I have found is this:

  • Open up Log Cat
  • Try and access Facebook with the Android SDK
  • Look for the line in the log that looks like this:

    04-24 01:14:08.605: I/System.out(31395): invalid_key:Android key mismatch. 
    Your key "abcdefgHIJKLMN+OPqrstuvwzyz" does not match the allowed keys specified in your
    application settings. Check your application settings at 
    http://www.facebook.com/developers
    
  • Copy "abcdefgHIJKLMN+OPqrstuvwzyz" and paste it into the Facebook Android Key Hash area.

查看更多
千与千寻千般痛.
7楼-- · 2018-12-31 04:33
  1. Simply Open you Main Activity File and create below mention function:

         try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "your.application.package.name",
                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 (PackageManager.NameNotFoundException e) {
    
    } catch (NoSuchAlgorithmException e) {
     }
    

1.1 Run you Application, this will generate a Hash key for your application.

  1. Now, Open log cat and search with "KeyHash" and copy the hash key.

  2. One you generate the Hash key you can remove this function.

查看更多
登录 后发表回答