and thanks in advance for your time and attention!
My android app that uses the facebook sdk runs nicely on the emulator, but i get onFacebookError() on both Samsung Galaxy S1 and S2 devices. I wish I could also supply you with more detailed error output information, but I currently do not have those devies at hand to debug on them and check whats going wrong with adb logcat. I know onFacebookError() method is running because of a Toast i put there displaying “onFacebookError”.
Until i manage to get those phones and investigate the errors and post them here, anyone encountered this issue before? When i searched here for this problam I read someone thinks this is because the official facebook app is installed on the devices. Is this relevent?
Toasting e.getMessage() to get the error details like this:
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
//Toast.makeText(MemoFriendActivity.this, "fbError", Toast.LENGTH_SHORT).show();
Toast.makeText(MemoFriendActivity.this, "MSG: "+e.getMessage()+ " CODE: "+e.getErrorCode(), Toast.LENGTH_LONG).show();
}
Displayed this message on S2 devices: “MSG: ivalid_key:Android key mismatch. Your key “XXX” does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers CODE: 0″
Code:
public void onClick(View v) {
// TODO Auto-generated method stub
if (MyUtil.fb.isSessionValid())
{
//button close session - log out of facebook
try {
MyUtil.fb.logout(getApplicationContext());
updateGuiAccordingToState();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
//login to facebook
MyUtil.fb.authorize(this, new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Toast.makeText(MemoFriendActivity.this, "fbError", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
Toast.makeText(MemoFriendActivity.this, "OnError", Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Editor editor = sp.edit();
editor.putString("access_token", MyUtil.fb.getAccessToken());
editor.putLong("access_expires", MyUtil.fb.getAccessExpires());
editor.commit();
getUsername();
updateGuiAccordingToState();
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(MemoFriendActivity.this, "OnCancel", Toast.LENGTH_SHORT).show();
}
});
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
MyUtil.fb.authorizeCallback(requestCode, resultCode, data);
}
My.Util.fb is a static Facebook object. Again, this code works on the emulator. Anybody knows how to solve it on a device? I hope I can look it up on a device soon and share.
Ok, got the answer myself. This is a mismatch of the android key. when running the app from a device instead of the emulator, you need to replace the Hash key that you got on your development PC to the one of the app on the phone has, which you can get from the output of e.getMsg like i showed here. get the key from your device, and set it up as the new Hash in facebook.com/developers. You can also add this hash key in addition to the one you have of your PC in case you want the app to work on both phone and PC. Hope this helps others.