Hey everyone just recently developed my first android app that logs into facebook and tries to status update Without the dialog box, using the graph API. The code below is the authorization code (which was on the fbook dev site itself) and it worked fine for me all along, until recently. Now my app logins in fine on my emulator but when I export the APK file and put it on my phone it gives me 'authentication error". Can someone explain this? It just doesn't show me the login page anymore, After I created a new keystore and hashkey AND updated that hashkey on my dev app page on facebook as usual.
I think it's due to the keyhash etc, but I dont understand that well enough to figure out what's wrong. What I do is, I click export, application, then I create a new keystore (the first time, otherwise I use existing keystore), then I find my hashkey using "keytool exportcert" etc as show on the fbook dev site. Then I enter that hashkey into the app on my facebook account. But sometimes even though the keystore password is correct it says "keystore format" is different, even though I used it before the same app! Then I have to create a new keystore, and exportcert again and all of that is a pain! There must be an easier way?
Can someone possibly explain how the hashkey for Facebook apps work as well?
Thanks in advance!
My Authentication Code :
public void login()
{
facebook.authorize(this,new String[] { "email", "read_stream", "publish_stream"}, new DialogListener(){
int fbcheck=0;
@Override
public void onComplete(Bundle values) {
fbcheck=1;
facebookauthcheck(fbcheck);
}
@Override
public void onFacebookError(FacebookError error) {
fbcheck=0;
facebookauthcheck(fbcheck);
}
@Override
public void onError(DialogError e) {
fbcheck=0;
facebookauthcheck(fbcheck);
}
@Override
public void onCancel() {
fbcheck=2;
facebookauthcheck(fbcheck);
}
});
}
public void facebookauthcheck(int fbcheck)
{
if (fbcheck == 0) {
Toast.makeText(this, "Authentication Error", Toast.LENGTH_LONG).show();
}
else if (fbcheck==1)
{
Toast.makeText(this, "Authenticated", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(this, "Authentication Cancelled", Toast.LENGTH_LONG).show();
}
Yeah I had this issue,
It worked fine on the emulator, worked fine on my dev phone, but failed on the test users phone.
It's to do with the Facebook app and SSO.
Have a read of this : http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/
It has 3 solutions.
I couldn't get SSO to work so I went for option two, (opt out of SSO!) This is done by:
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, this);
If you want to fix it and get SSO to work:
Correctly generate your hash key for the debug apk certificate. (detailed in the link above).
Ref:
Corresponding SO Question
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