1

I am using this simple code from here:

https://developers.facebook.com/docs/mobile/android/build/#sig

public class MainActivity extends Activity {

    Facebook facebook = new Facebook("xxxxxxxxxxxxxx");
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    private SharedPreferences mPrefs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        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);
        }

        if (!facebook.isSessionValid()) {
            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();
                }

                @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);
        try {
            JSONObject json = Util.parseJson(facebook.request("me"));
            String facebookID = json.getString("id");
            String firstName = json.getString("first_name");
            String lastName = json.getString("last_name");
            String email = json.getString("email");
            String gender = json.getString("gender");

        } catch (Exception e) {

            //If i click Okay i get Exception saying You need an Active access token to get the current user details
        }

    }
}

got Hash key using this:

enter image description here

which asks for a password ("android")

and gives me a code like this:

xLYMxxxxxx/0enePexxf4DORUfR8=

and in facebook application my configurations are:

enter image description here

But i get this Error:

enter image description here

and if i press Okay i get the Exception saying You need an Active access token to get the current user details.

I tried all possible solutions given on SOF. But of no use. Please help

Thank You

avb
  • 1,558
  • 1
  • 14
  • 37
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • Look into com.facebook.android.Utils class code. set private static boolean ENABLE_LOG = true; And observe LogCat output when you are trying to login. – Agata Oct 24 '12 at 12:48
  • Yeah.it was always true, and never shown me anything in the logcat. :( – Archie.bpgc Oct 24 '12 at 12:50
  • I had "is misconfigured for login" error too. After sometime it turned out Facebook wanted different keyhash then i had, for some reason. – Agata Oct 24 '12 at 12:52
  • how did you get the new hash key?? – Archie.bpgc Oct 24 '12 at 12:53
  • After some time of debugging it came to me in LogCat output ;/ Something like this "Login failed: invalid_key:Android key mismatch. Your key "XXXXXXXXXXXXXXX" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers" And i would personally put JSON parsing into LoginListener. And put Logs inside of Listner in onFacebookError and onError to see if you get any errors from here. – Agata Oct 24 '12 at 12:54
  • can please tell me the Openssl version you used? – Archie.bpgc Oct 24 '12 at 12:57
  • OpenSSL 0.9.8r 8 Feb 2011. Also you don't put any permissions for Facebook login. You could look at that. – Agata Oct 24 '12 at 13:01
  • Okay. But its still the same. Not working >. – Archie.bpgc Oct 24 '12 at 13:11

1 Answers1

2

It seems like you didn't get your hash key correctly from the terminal.

Try this instead

  1. Enable logging by going to the Facebook SDK source Util.java and set ENABLE_LOG to true.
  2. Try logging into your app again and you should still see the red error message. Press OK.
  3. Go to your logcat and find an entry that looks something like this:

D/Facebook-authorize(24739): Login failed: invalid_key:Android key mismatch. Your key "uk3udeH7vrOGNFH2FJjdJbdWJWI" does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers

Copy and paste that key into your dashboard and try again.

See this SO thread: App is misconfigured for Facebook login : Android Facebook integration issue

Jesse Chen
  • 4,928
  • 1
  • 20
  • 20
  • the problem was: the logcat doesn't show any error. But after several restarts i finally got the error you pasted. But i have a doubt. The has key given in error is same except for the **=** in the end of the hash key i am using in configuration. So should i remove that **=**?? Thank You – Archie.bpgc Oct 25 '12 at 07:38
  • No, you should paste exactly what it says. The = sign is part of the key hash – Jesse Chen Oct 25 '12 at 19:54
  • eww. But it works only without **=**. Should i use the 1 i get in the terminal using keytool or the 1 i get in the logcat error message?? – Archie.bpgc Oct 26 '12 at 04:48
  • the one in the logcat error message is guaranteed to be the correct hash while the keytool command can return wrong ones if your setup isn't correct, so I would go with the one in the error msg – Jesse Chen Oct 26 '12 at 21:15
  • ENABLE_LOG cannet be changed anymore since December 2012: https://github.com/facebook/facebook-android-sdk/commit/30d9ebd42074dbfbb2d102f2ccfaa96e0ef8c490#facebook/src/com/facebook/android/Util.java – Pascal Klein Feb 24 '13 at 03:41