ToByteArray () will not be allowed to enter facebook

I am creating an application that requires facebook login and authentication.

I follow

https://developers.facebook.com/docs/android/getting-started#create-app

I got this error: when I clicked the facebook login button:

enter image description here

Several posts say this code should fix the error

Cache hash does not match when logging into facebook on android

:

try { PackageInfo info = getPackageManager().getPackageInfo( "com.hitup.hitup", 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) { } 

however, the toByteArray () method cannot be resolved!

enter image description here

How can I resolve this error and achieve a simple facebook login for my application?

+7
java android facebook facebook-android-sdk
source share
2 answers
+43
source share
 from Logcat you can get hash key of facebook please do copy from logcat which having Logcat tag "KeyHash" and put it in your project on developer.facebook site 

enter image description here

 import android.content.pm.Signature; try { PackageInfo info = getPackageManager().getPackageInfo( **"do not forgot to your 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 (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } OR 1. for Android default keystore : add this to in your terminal keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 2. for signed keystore keytool -exportcert -alias aliasname -keystore keystorename | openssl sha1 -binary | openssl base64 
+6
source share

All Articles