Key hash for Android-Facebook app

后端 未结 30 2688
误落风尘
误落风尘 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条回答
  • 2020-11-22 01:53
    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.

    0 讨论(0)
  • 2020-11-22 01:53

    I did a small mistake that should be kept in mind. If you are using your keystore then give your alias name, not androiddebugkey...

    I solved my problem. Now if Facebook is there installed in my device, then still my app is getting data on the Facebook login integration. Just only care about your hash key.

    Please see below.

    C:\Program Files\Java\jdk1.6.0_45\bin>keytool -exportcert -alias here your alias name  -keystore "G:\yourkeystorename.keystore" |"G:\ssl\bin\openssl" sha1 -binary | "G:\ssl\bin\openssl" base64
    

    Then press Enter - it will ask you for the password and then enter your keystore password, not Android.

    Cool.

    0 讨论(0)
  • 2020-11-22 01:54

    You need to create a keystore by the keytool for signed apps for android like the procedure described in Android Site and then you have to install cygwin and then you need to install openssl from google code then just execute the following command and you will get the hash key for android and then put that hash key into the facebook application you created. And then you can access the facebook application through the Android Application for posting wall ("publish_stream") could be an example.

    $ keytool -exportcert -alias alias_name -keystore sample_keystore.keystore | openssl sha1 -binary | openssl base64

    You need to execute the above command from cygwin.

    0 讨论(0)
  • 2020-11-22 01:54

    For an Android application

    This code is used to get the hash key in your Android application for Facebook integration. I have tested all devices and it's working. Only change the package name of this code:

    private void facebookHashKey() {
    
        try {
            PackageInfo info = getPackageManager().getPackageInfo("com.app.helpcove", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hashCode  = Base64.encodeToString(md.digest(), Base64.DEFAULT);
                System.out.println("Print the hashKey for Facebook :"+hashCode);
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (NameNotFoundException e) {
    
        } catch (NoSuchAlgorithmException e) {
    
        }
    }
    
    0 讨论(0)
  • 2020-11-22 01:55

    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.

    0 讨论(0)
  • 2020-11-22 01:55
    • download openSSL for windows in here you can find 64bit and 32bit here

    • extract the downloaded file

    • create folder name openSSL in C drive
    • copy all the extracted items in to openSSL folder (bin,include,lib,openssl.cnf)
    • get android debug keystore, default location will be

    C:\Users\username\.android\debug.keystore

    • now get your command prompt and paste this code

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

    • hit enter and you will get the 28 digit keycode
    0 讨论(0)
提交回复
热议问题