Facebook Android Generate Key Hash

后端 未结 21 2063
误落风尘
误落风尘 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 05:09

    Hi everyone its my story how i get signed has key for facebook

    first of all you just have copy this 2 methods in your first class

        private void getAppKeyHash() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md;
    
                md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String something = new String(Base64.encode(md.digest(), 0));
                System.out.println("HASH  " + something);
                showSignedHashKey(something);
    
            }
        } catch (NameNotFoundException e1) {
            // TODO Auto-generated catch block
            Log.e("name not found", e1.toString());
        } catch (NoSuchAlgorithmException e) {
    
            Log.e("no such an algorithm", e.toString());
        } catch (Exception e) {
            Log.e("exception", e.toString());
        }
    }
    public void showSignedHashKey(String hashKey) {
    
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle("Note Signed Hash Key");
        adb.setMessage(hashKey);
        adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
    
            }
        });
    
        adb.show();
    }
    

    **Call funcation getAppKeyHash() from your oncreate methode if you want signed hash then make signed build install signed build and run you will get hash key in dialog then just note it and update it on facebook dev account and comment that function and make another signed APK **

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

    use this in kotlin for print key hash in log

    try {
            val info = context.getPackageManager().getPackageInfo(context.packageName,
                    PackageManager.GET_SIGNATURES);
            for (signature in info.signatures) {
                val md = MessageDigest.getInstance("SHA")
                md.update(signature.toByteArray())
                Log.d("Key hash ", android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT))
            }
        }catch (e:Exception){
    
        }
    
    0 讨论(0)
  • 2020-11-22 05:11

    One line solution to generate for facebook

    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
    
    0 讨论(0)
提交回复
热议问题