I'm getting login failed invalid key error
while using an updated version of Facebook. If I delete it - it's working fine..
What is the correct way of creating a hash key?
I know that there are a lot of questions and answers for single sign on in Android, but none helped me to implement single sign-on in Android.
My code:
public class Main extends Activity {
Facebook facebook = new Facebook("XXXXXXXXXX");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
Then I generated a hash key using the command
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Also, I am having OpenSSL and given the location of OpenSSL upto openssl.exe
..
After I hit Enter it is asking for a password and I gave android as the password. Then I got a key and filled in "My Application".
The correct way to create a hash key
Please follow the following steps.
Here are the steps:
Download OpenSSL from Google Code
Extract it. Create a folder- OpenSSL in C:/
and copy the extracted code here.
detect the debug.keystore
file path. If you don't find it, then do a search in C:/
and use the path in the command in next step.
detect your keytool.exe
path and go to that dir/ in a command prompt and run this command (in one line):
$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
it will ask for a password. Put "android", that's all. You will get a key-hash.
First, you need to create the hash key using the below code according to your path.
C:\Documents and Settings\Logistic103>keytool -export -alias androiddebugkey -keystore "C:\Documents and Settings\Logistic103\.android\debug.keystore" | E:\Downloads\openssl-0.9.8k_WIN32\bin\openssl.exe sha1 -binary | E:\Downloads\openssl-0.9.8k_WIN32\bin\openssl.exe enc -a -e
Then enter the password:
Enter keystore password: android
Then go to Facebook developers and login into Facebook. After login goto your application and click on edit setttings link:
Then add the generated key as under to your application,
And that's how you do it ;)
The above steps works well for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With