0

I'm having a very annoying problem using Facebook's sign-on. It works perfectly fine when running on an emulator, but when trying to use it on an actual device causes the following to happen: I see the facebook page loading, for a few seconds, and then nothing.

_facebook = new Facebook(Common.APP_ID);
_facebook.authorize(this, new DialogListener() {
    @Override
    public void onComplete(Bundle values) {
        try {
            JSONObject json = new JSONObject(_facebook.request("me"));
            String id = json.getString("id");
            String token = _facebook.getAccessToken();
            Log.w("facebook", id);
            Log.w("facebook", token);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public void onFacebookError(FacebookError error) {
        Log.w("facebook", "onFacebookError");
    }
    @Override
    public void onError(DialogError e) {
        Log.w("facebook", "onError");
    }
    @Override
    public void onCancel() {
        Log.w("facebook", "onCancel");
    }
});

I get no logs saying anything is wrong, it does not stop at any of the onError methods, nothing. Just carries on as usual. I've followed everything written online, I've added the native app ID gotten using the keytool to the app page, and still - NADA.

Any help (even a workaround) would be greatly appriciated! Thanks

Gal
  • 5,338
  • 5
  • 33
  • 55
  • Have you implemented the onActivityResult() method within your Activity as required by Facebook SDK? – harism Dec 28 '11 at 22:06
  • do u have any other facebook app already installed on the device? – Andro Selva Dec 29 '11 at 04:47
  • @harism that solved it! I can't believe I missed that! If you want me to accept it as a solution, post it as an answer instead of a comment :) – Gal Dec 29 '11 at 14:56

3 Answers3

1

Since @harism isn't posting his comment as an answer, I figured I would at least to have an answer on this question.

What I missed was having this piece of code

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    _facebook.authorizeCallback(requestCode, resultCode, data);
}

Why it would on an emulator without it but not on an actual device is something I'm not entirely sure, but using this code does cause the SSO to work on my device.

Gal
  • 5,338
  • 5
  • 33
  • 55
0

As a workaround you can just force facebook to use Facebook.FORCE_DIALOG_AUTH. I'm having the ame problem at the moment and this is the only thing I could find that works :/

stork
  • 420
  • 1
  • 3
  • 12
0

You need to get the Android hash key using the command below and put it in your facebook app configuration at developer.facebook.com/apps

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

For more info, here is a really useful blog post: http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/

Ibrahim Muhammad
  • 2,808
  • 4
  • 29
  • 39