i try to generate Key Hash for facebook SDK Mac.i searched and i found solution
keytool -exportcert -alias myalias -keystore myapk.keystore | openssl sha1 -binary | openssl base64
and i recived keyhash and i inserted this keyhash my developerfacebook page.
but i have error invalid keyhash.
My appliacation can use facebook sdk ,i can login facebook but,
i have error when divice use also facebook aplication.I have no ideaa what is i am doing wrong.
if anyone knows solution please help me
thanks
Try to use the following code in the onCreate method and obtain the Keyhash, place it in the keyhashes section. Hope it works
private void getKeyHash(Context context) {
try {
PackageInfo info = getPackageManager().getPackageInfo("com.example.android", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("Obtained KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
Related
I use Window 7 with android studio to build my application.
I used in facebook SSO for the login system. I follow the steps
as the below tutorial.
How to create Android Facebook Key Hash?
I inputted the command as below into my powershell
$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
Then the powershell return a hash shorter than 28 chars, which is not accepted by facebook.
How can I generate a key accepted by facebook?
You need to use this hashkey generated by below code:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageInfo(pContext, 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);
}
}
I got the same problem when I provided invalid keystore path - no error message, just strange eight-character-long string. Switching path to
C:\Users\Username.android\debug.keystore
solved the problem in my case.
It happened to me when i use openssl-0.9.8k_WIN32.zip,generated only TenDigitHash== then i returned to using openssl-0.9.8e_WIN32.zip so it generated hash as expected. I am using windows32bit
I'm trying to use Facebook Android SDK to develop a simple app with the Facebook Login Button. But i'm having trouble with Key Hashes. I've created both a debug key and a release key:(in mac)
Debug key:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
i also tryed this code also
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.me", PackageManager.GET_SIGNATURES); //Your package name here
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) {
}
}
And then i copied this key hashes in the Facebook Developers page.when i run my app with eclipse then working.but When i export the apk and copy it into the device it does not working.
also i have another problem.if my divice has installed Facebook Application then also not working.
how i can solve my problem?
When you get Invalid key hash, it also shows the correct key hash and says "The keyhash XXXXX didnot match with any of the stored keyhashes" . so copy that displayed keyhash and append "=" at the end as XXXXX= and add it in the key hash section. Hope it works....
this might also work
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.me", PackageManager.GET_SIGNATURES); //Your package name here
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) {
}
}
I am working on a android app and has to provide the hashkey to facebook. I have tried 3 appoarch but none of them works.
By following the official doc:
1.) I write a command in windows like this
"C:\Program Files\Java\jdk1.7.0_17\bin\keytool.exe" -exportcert -alias androiddebugkey -keystore C:\hk7.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
output:
57GY9jCxTL9lwhI9oAsjNZN1UJ4=
2.) And the programatically way
try {
PackageInfo info = getPackageManager().getPackageInfo("com.package.mypackage", 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);
Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
output:
PH//aR6qmcnZxj/n+4oT6AzEMZQ=
Works but only for my device
3.) the alias value
keytool -alias hk7 -exportcert -keystore C:\hk7.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
output:
kiHnmqD3oxggF1Y7rgTqaWTPZk4=
Only the second way works but it is only for my device . In my app , I log the exception , it said the API key does not match . but it seems each device has its own key. How to fix that? and is it caused my openssl is too old? or the android side implementation problem? Are there any site for testing whether the key is work? Thanks for helping
2nd way is t best one, Now you need to add every device hashkey on which you want to test as your app is not on playstore .. once you upload t app on playstore/sign with a perticular keystore then you have to add only that keyhash.... Use this function to get KEYHASH
private void printKeyHashForThisDevice() {
try {
PackageInfo info = getPackageManager().getPackageInfo("com.package", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Logger.logger("============================================");
Logger.logger("KeyHash================ ", keyHash);
Logger.logger("============================================");
System.out.println("KeyHash================ " + keyHash);
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
Hy! I tried to integrate the facebook sdk with my android app. I obtain my key kashes using this comand:
keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
After that I, i create a new facebook application, where i selected native android app and i give my hashkey.
But when I run the app, I receive this error:
Can someone to help me?
Try this when session open
try {
PackageInfo info = getPackageManager().getPackageInfo("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) {
}
Sorry for asking the same question, but I read all the threads posted before and tried everything suggested, but I was still unsuccessful.
I am getting the same:
App is misconfigured for Facebook login.
The issue looks same as here, but I could not get the Logcat printed as an error in red even after setting ENABLE_LOG to true in util.java.
I have checked my app_id and copied the hash key in developer.facebook, and everything looks right. But I don't know where I am going wrong and also that I am getting it right when I use the app without native Facebook app.
But I want to login using native Facebook.
Assuming you're using the latest 3.0 SDK, try the following two options:
Option 1: (Windows)
%KEYTOOLPATH%\keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | %OPENSSLPATH%\openssl sha1 -binary | %OPENSSLPATH%\openssl base64
Example:
C:\Program Files (x86)\Java\jdk1.7.0_09\bin\keytool" -exportcert -alias androiddebugkey -keystore "C:\Home\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64
Use the password: android
Option 2: (Print key hash sent to FB)
(A variation of Facebook SDK for Android - Example app won't work)
Add this code to your activity:
try {
PackageInfo info = getPackageManager().getPackageInfo("your package name, e.g. com.yourcompany.yourapp]", 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) {
}
Example:
In HelloFacebookSampleActivity, make the following temporary modification to the onCreate() method
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.hellofacebook", 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) {
}
...
}
Run your sample and you should get logcat output on the KeyHash tag similar to:
12-20 10:47:37.747: D/KeyHash:(936): 478uEnKQV+fMQT8Dy4AKvHkYibo=
Use that value in Facebook's App Dashboard settings for your app.