Facebook Android Generate Key Hash

后端 未结 21 2030
误落风尘
误落风尘 2020-11-22 04:11

Trying to create an android app with Facebook integration, I\'ve gotten to the part in the docs where you have to generate a key hash file, it specifies to run the following

相关标签:
21条回答
  • 2020-11-22 04:58

    At last :)

    Here my story :

    1. Add this code to your main activity, after you set layout.

      try { 
        PackageInfo info = getPackageManager().getPackageInfo("PROJECTNAME", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:", sign);
            //textInstructionsOrLink = (TextView)findViewById(R.id.textstring);
            //textInstructionsOrLink.setText(sign);
            Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
        }
      } catch (NameNotFoundException e) {
          Log.d("nope","nope");
      } catch (NoSuchAlgorithmException e) {
      }
      
    2. Change PROJECTNAME to your package name!

    3. Sign your app (Android Tools->Export Signed Application)
    4. In your main activity where you paste code from 2 option, in your layout create TextView with id textstring
    5. uncomment two lines, that your sign code would be set to TextView 6 Wuolia, you have your HASH , install app on your phone!!! and check your hash Key!
    6. Now when it is visible , go to facebook app you created and add it to [Key Hashes]
    7. Note that your package name should be same as on facebook [Package Name] under [Key Hashes]
    8. Have a nice day :)
    0 讨论(0)
  • 2020-11-22 04:58

    Even though this thread is old, yet I would like to share my experience (recently started working with facebook), which seems to me straight:

    1. Download openssl from the link bellow: https://code.google.com/p/openssl-for-windows/downloads/list
    2. Unzip it to a local drive (e.g., C:\openssl)
    3. To get the Development key for facebook integration, use the following command from the command line in windows:

      keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64

    NOTE!: please replace the path for openssl.exe (in this example it is "C:\openssl\bin\openssl.exe") with your own installation path.

    1. It will prompt for password, e.g.,

    Enter keystore password: android

    Type android as password as shown above.

    Thats it! You will be given a 28 character long key. Cheers!

    Use the same procedure to get the Release key. Just replace the command with the following and use your release key alias.

    keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | "PATH FOR openssl.exe" sha1 -binary | openssl base64

    0 讨论(0)
  • 2020-11-22 04:59

    I. Create key hash debug for facebook

    Add code to print out the key hash for facebook

        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.google.shoppingvn", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.i("KeyHash:",
                        Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (NameNotFoundException e) {
    
        } catch (NoSuchAlgorithmException e) {
    
        }
    

    II. Create key hash release for facebook

    1. Download openssl-0.9.8e_X64

    2. Make a openssl folder in C drive

    3. Extract Zip files into openssl folder

    4. Start -> Run: cmd (press enter)

    5. (press) cd C:\Program Files\Java\jdk1.6.0_45\bin. Note: C:\Program Files\Java\jdk1.6.0_45\bin: is path to jdk folder in your computer

    6. (press) keytool -exportcert -alias gci -keystore D:\folder\keystorerelease | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl base64. Note: D:\folder\keystorerelease: is path to your keystorerelease

    7. Enter keystore password: This is password when your register keystorerelease.

      Then you will have a key hash: jDehABCDIQEDWAYz5Ow4sjsxLSw=

    8. Login facebook. Access to Manage Apps. Paste key hash to your app on developers.facebook.com

    0 讨论(0)
  • 2020-11-22 05:00

    If your password=android is wrong then Put your pc password on that it works for me.

    And for generate keyHash try this link Here

    0 讨论(0)
  • 2020-11-22 05:00

    The only thing working for me is using the password android. Why is that not mentioned in any guides out there?

    0 讨论(0)
  • 2020-11-22 05:02

    Simplest way to generate hash key.

    Requirement: SHA1 Key

    You can get SHA1 Key from your keystore file by two ways

    1) Locate your keystore file, open command prompt on that location then use below mentioned command

    keytool -list -v -keystore {keystore_name} -alias {alias_name}
    

    and then enter your password then it will return md5, sha1 and sha256 key.

    OR

    2) By running signingReport

    Refer below image.

    after you run the file your output will be generated containing required sha1 key.

    After you get the required SHA1 Key

    Then goto

    http://tomeko.net/online_tools/hex_to_base64.php

    and paste your sha1 key

    and finally you will get Required HashKey which you can use it to apply on facebook.

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