Yarh
Yarh

Reputation: 4607

How to get key hashes for facebook for facebook app?

I making keyhashes using this command

keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64

to generate debug and release keyhash. However, pair of those keys works only when facebook app is not installed on device. If it is installed another pair of hashes is required (4 keys in total) and i don't anderstand how to get those 2 keys (I am getting them when facebook sdk returns error message xxxx key is not registered)

Upvotes: 0

Views: 1310

Answers (1)

Karthik
Karthik

Reputation: 1219

Try like this

public static void printHashKey(Context pContext) {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hashKey = new String(Base64.encode(md.digest(), 0));
                Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
            }
        } catch (NoSuchAlgorithmException e) {
            Log.e(TAG, "printHashKey()", e);
        } catch (Exception e) {
            Log.e(TAG, "printHashKey()", e);
        }
    }

This will generate debug key hash, if you want release key hash, select build variants in android studio and then change debug to release. Now again run the above method this will generate release key hash.

Upvotes: 1

Related Questions