I'm trying to put my debbug hash key, which is : "e3U9nzK7A8gyWoCiNUZQA/C+bZI=".
But every time i put it inside the key hash section on my Facebook App it changes to "e3U9nzK7A8gyWoCiNUZQA%2FC%2BbZI%3D" automatically, making my app useless.
I used two methods to get this key, and it returned the same : keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
and :
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));
Log.d("Hash key", something);
}
}
catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
Log.e("no such an algorithm", e.toString());
}
catch (Exception e){
Log.e("exception", e.toString());
}
}
Try out this
try {
PackageInfo info = getPackageManager().getPackageInfo(com.domain,
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("PXR", com.domain.Base64.encodeBytes(md.digest()));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
I have the same problem, and realised this is a bug on facebook´s end. See link. Very anoying.
Edit
The only working solution (but ugly) until it is solved seems to be to force login through web interface, since SSO is the one using the hashkey.
If using the login-button:
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
Source: Android - Force Facebook connection - Stack Overflow
Edit 2
It can be solved though; I asked a friend (over Skype, he´s on a mac) to add them for me. And he managed to get it right (but I do not know how).
Edit 3
Now this issue seems to have solved itself for me. Entered hashkeys no longer gets rewritten. Whether it is solved by fb-team or just required a computer restart from me I do not know.
Related
Hi I'm very new to facebook login. I tried to generate a hash key for facebook android app. The first time it didn't asked for a password and gave me the hash key but now when I again tried to generate the hash key its asking for pass. When I enter "android" as pass, it gives me just DrNQ.
command used:
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Sam\.android\debug.keystore" | "C:\Openssl\bin\openssl" sha1 -binary | "C:\Openssl\bin\openssl" base64
you are using to much complex trick to get hash key of your application it's having lots of chance to get error.But I have one simple idea to generate your application hash key.
for generating hash key you must need to specify your package name and you are just putting following code while app is lunch and you are getting yout app hash key in Log.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.example.chirag.maptesting",
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));
Toast.makeText(Main2Activity.this, "Hash Key :"+Base64.encodeToString(md.digest(), Base64.DEFAULT), Toast.LENGTH_SHORT).show();
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
Note :
in Above code com.example.chirag.maptesting is my application package name but you must need to paste your package name here.
I hope your are clear with my idea.
Best Luck
Using below code snippet, you can get the hash code.
public static String printKeyHash(Activity context) {
PackageInfo packageInfo;
String key = null;
try {
//getting application package name, as defined in manifest
String packageName = context.getApplicationContext().getPackageName();
//Retriving package info
packageInfo = context.getPackageManager().getPackageInfo(packageName,
PackageManager.GET_SIGNATURES);
Log.e("Package Name=", context.getApplicationContext().getPackageName());
for (Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
key = new String(Base64.encode(md.digest(), 0));
// String key = new String(Base64.encodeBytes(md.digest()));
Log.e("Key Hash=", key);
}
} catch (NameNotFoundException e1) {
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());
}
return key;
}
I got hash key from below code in android:
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
}
catch (NameNotFoundException e1) {
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());
}
But it was invalid key... Please suggestion how to verify hash key for Facebook login....
You are getting the hash-key with debug key... Which may work if you haven't sign the package and running app in debug mode. What you need to do is :
1) Go to the manifest file and add to the application android:debuggable="true".
2) Sign the application, capy and install to your device manually or for use "adb install path_to_apk" from command line.
3) Now run your app and monitor the logcat.
4) You will get printed a new key which will be the matching key with key facebook app is showing in the error msg, The key you have got is now having a = sign in the last.
5) Register this key on facebook developer site
Alternate Trick
You can do one other thing Simply register key which is showing in the error msg "The key hash ### does not match any stored key hashes" Just add the = in the end of the ###. It will be like ###=
you are done!! Hope this will work.
Add this function into your class,and call this function in oncreate methode,then generate sign apk and run sign apk in your device and check log-cat, copy generated hash key to facebook developer console.
private void showHashKey()
{
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.kisan.kisan",
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) {
}
}
Check facebook authentication,it will work fine
I think the issue is you might not have updated the keyhash in the facebook developer account. Refer the: https://developers.facebook.com/docs/android/getting-started
Generate the Keyhash using:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
And update into your facebook devloper site, under Apps tab, General Settings
Assign this to a button's on click and get the Key Hash from the logcat.
Button getKeyHash = (Button) findViewById(R.id.button_key_hash);
getKeyHash.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Key Hash
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e1) {
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());
}
}
});
Now go to your app at https://developers.facebook.com/apps
. Then click on settings, add your Key Hash and save.
i just implemented Facebook log in into my android application. when i try to log in with Facebook i got following exception in log-cat.
Error Log :
com.facebook.http.protocol.ApiException: Key hash oZgj_um2MGi1eYpfTqwytjLMN10 does not match any stored key hashes
I already added this key hash into my developer account app page.But still i am facing same issue.
Your HashKey is wrong. It should have 28 characters while your hash key 27 characters the hashkey always ends with =. So I think you have missed it. Please check it again and
Change your hashkey by generating it programatically from the following code given in Facebook Docs and defined at Facebook Integration in Android Application
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.example.yourpackagename", 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));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
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());
}
I'm trying to generate Key hash to incorporate Facebook Application in my Apps.
The problem is that;
I'm actually getting the right key hash, but i'm still getting the wrong app key hash.
(Maybe I'm not taking the right part from the whole key..)
Any help will be very appreciated, I'm pretty lost here...
Problem Fixed! :
Just needed to get rid of the "=" sign after copying the key from the CMD.
Please let us know how you are getting your Key-Hash. If from keytool, then let us know the procedure, may be we will be able to fix, what are your missing.
In the meantime you can use the following code to get the Key-Hash.
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));
Log.d("Hash key", something);
}
}
catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
Log.e("no such an algorithm", e.toString());
}
catch (Exception e){
Log.e("exception", e.toString());
}
}
Now from the logcat you can find the Key-Hash. For more info Please check it form facebook-sdk
Problem Fixed! :
Just needed to get rid of the "=" sign after copying the key from the CMD.
I have recently started working on facebook API, where I came under the situation of generating Hash key and registering it on facebook for further use.
For that, I used the following code
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.you.name", 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));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
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());
}
All worked well, as I was able to work with facebook in my app.
But, after publishing the app on playstore, I found the error Invalid_Android_key parameter. The key does not match any allowed key Configure your app key hashes at https://developers.facebook.com/apps/..........
Please, let me know the cause of this problem and how to handle this.
I had same Problem, after creating the apk, the key hash is changed! because using this code u get the debug keystore hash, but when creating apk, it's another hash, gotta capture it from log after trying ur apk on emulator , then delete code and export again without this log , i know it's a hassle but for me it was easier than keytool...