问题
So I've got a facebook SSO implemented in my Android app with sending a post to the FB wall. All the time throughout the development, both in emulator and on my phone, everything worked just fine. I've supplied the hash from my debyg.keystore to FB app, all fine. Now when I have exported my ready app and signed it I have produced a new hash for the release key and put it in the apps settings. When installed it still works perfectly on my phone but doesn't on anyone else's. So I've connected another phone and checked the logs while trying to send the message to the wall. Getting the fallowing response each time:
02-10 19:41:04.802: D/Facebook-authorize(26750): Login failed: invalid_key:Android key mismatch. Your key "pwrvr9ALAVF7yAL5pKmGWRwR8i0" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers
I've re-installed on my phone numerous times and on other phones but still the same. Here's the snippet of code that leads to either authorization and then posting to the wall or to posting straight to the wall :
// Check if connected to the internet first
if (connected())
{
//Get existing access_token if any
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null)
{
facebook.setAccessToken(access_token);
}
if(expires != 0)
{
facebook.setAccessExpires(expires);
}
// Only call authorize if the access_token has expired.
if(!facebook.isSessionValid())
{
facebookAuthorizeAndPost(msg);
}
else
{
posToFBWall(msg);
}
}
else
{
Toast.makeText(getBaseContext(), "There's been a problem connecting to Facebook. Please make sure you're connected to the internet and try again", Toast.LENGTH_SHORT).show();
}
And here's the snippet that does the actual authorization and delegates to postToFBWall() method if successful:
private void facebookAuthorizeAndPost(final String msg)
{
facebook.authorize(this, new String[] {}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
if (values.containsKey("access_token"))
{
posToFBWall(msg);
}
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
Doing something wrong here? More to the point, what the Android key mismatch error mean, why does it occur? Anyone ideas, pointers appreciated.
回答1:
Based upon the error, I suspect that it is a key problem, and that it was generated incorrectly. Sometimes the keyhash instructions simply do not work. I have run into similar problems with getting the correct keyhash, despite following the instructions to the T.
That said, and just to be sure you have the correct key, I recommend using an android program that will tell you the correct keyhash, such as: http://www.easyfacebookandroidsdk.com/download/keyhash.zip
All you need to do is import the project and sign it with the same keystore that you will sign your facebook application with. Then just install and run it, and it will display the keyhash.
EDIT
You may also want to double check that your key, "pwrvr9ALAVF7yAL5pKmGWRwR8i0" is actually listed as one of the keys for your app on the developer page.
回答2:
I dont know if your problem is resolved right now but I was having the same problem as you and now I find the complete solution.
You have two enviroments for the development: debug and a signed application, when you use this commands to get your key (keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64) you are getting the key for the debug.keystore, but when you sign the app you get a new key because your app is using a new keystore (the keystore created for you). You can get your "sign app key" using the program that TomJ recommended http://www.easyfacebookandroidsdk.com/download/keyhash.zip but you have to sign with the same keystore that you are using in your app.
来源:https://stackoverflow.com/questions/9240416/android-facebook-sso-login-failed-invalid-keyandroid-key-mismatch