Key hash for Facebook Android SDK

前端 未结 9 1901
后悔当初
后悔当初 2020-11-28 03:29

I can\'t figure out how to get the Key Hash required to use the Facebook Android SDK. I figured out that I can use keytool with these commands:

         


        
相关标签:
9条回答
  • 2020-11-28 04:00

    You have to open a command prompt window. Go to start->run and type 'cmd' and hit enter. Then you have to navigate to the folder where keytool is (unless it's in your path), and then type that command.

    That is, assuming that command is for windows and not linux.

    0 讨论(0)
  • 2020-11-28 04:02

    Best way is to generate Key-Hash using code:

     public static void generateKeyHash(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    "com.example.user2.testapp",
                    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) {
    
        }
    }
    

    call this method once and generate key-hash, enjoy

    0 讨论(0)
  • 2020-11-28 04:06
    1. Download and install OpenSSL from http://slproweb.com/products/Win32OpenSSL.html based on windows 32 or 64 bit.(Note: Download and install first visual C++ 208 redisributable from that site also )
    2. Put the bin directory of installed OpenSSL in windows path.
    3. Open the command prompt and go to C:\Users{User_Name}.android
    4. now put this command on cmd "keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64".(refer https://developers.facebook.com/docs/android/getting-started#samples)
    5. Now enter password "facebook" without double quote.
    6. Now a hash key will be generated enter image description here
    7. Finally go to the Facebook Developer site. Make sure you are logged into Facebook and, using the dropdown menu in the top-right, go to your 'Developer Settings':
    8. Once you're in your developer settings, select 'Sample App' from the navigation on the left, and add and save your key hash into your profile: enter image description here
    0 讨论(0)
  • 2020-11-28 04:10

    You can install Open SSL from here , that should make your command work

    0 讨论(0)
  • 2020-11-28 04:11

    you can use code below to get the Hash key :

    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) {
       Log.e("name not found", e.toString());
      } catch (NoSuchAlgorithmException e) {
       Log.e("no such an algorithm", e.toString());
      }
    

    Reference :

    http://limbaniandroid.blogspot.com/2013/04/how-to-get-hash-key-for-integarte.html

    0 讨论(0)
  • 2020-11-28 04:16

    C:\Program Files\Java\jdk1.6.0_22\bin\keytool.exe -exportcert -alias "typeYouraliasname" -keystore locationof your keystore | C:\OpenSSL-Win32\bin\openssl sha1 -binary | C:\OpenSSL-Win32\bin\openssl base64

    0 讨论(0)
提交回复
热议问题