qwerty_gr
qwerty_gr

Reputation: 318

logging in to facebook from my app works on emulator but not on device

This is my code for logging in to facebook.

mLoginButton = (LoginButton) findViewById(R.id.login);

        // restore session if one exists
        SessionStore.restore(Utility.mFacebook, this);
        SessionEvents.addAuthListener(new FbAPIsAuthListener());
        SessionEvents.addLogoutListener(new FbAPIsLogoutListener());

        /*
         * Source Tag: login_tag
         */
        mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);

        if (Utility.mFacebook.isSessionValid()) {
            requestUserData();
        }
 public class FbAPIsAuthListener implements AuthListener {

        //@Override
        public void onAuthSucceed() {
            requestUserData();
        }

        //@Override
        public void onAuthFail(String error) {
            mText.setText("Login Failed: " + error);
        }
    }

    /*
     * The Callback for notifying the application when log out starts and
     * finishes.
     */
    public class FbAPIsLogoutListener implements LogoutListener {
        //@Override
        public void onLogoutBegin() {
            mText.setText("Logging out...");
        }

        ///@Override
        public void onLogoutFinish() {
            mText.setText("You have logged out! ");
            mUserPic.setImageBitmap(null);
        }
    }

On emulator it works perfect. I have tried in ton 3 devices, that have already facebook installed and here is the problem.

it just spinning aroun on loading and it does nothing. I see the login button again. Then i tried to logout from the original facebook application, and when pressing the login button on my app, i see the login window but now that I used to see when logging in the emulator but the login window of the original facebook application. Like is has started this one.

the code I am using is taken from the hackbook.java

Upvotes: 7

Views: 5812

Answers (2)

kamal_tech_view
kamal_tech_view

Reputation: 4255

You need to generate the hash key of your system and just place it by editing the existing facebook App.

Upvotes: 0

Nitzan Tomer
Nitzan Tomer

Reputation: 164139

The Platform Status says that there's a problem with the SSO.

The SSO only works if you have the facebook application installed on the android device, and what you describe fits right into all of this. On the emulator you don't have the facebook application, and so when your application tries to log the user in it uses the dialog it has in the sdk instead of using the SSO process that ships with the fb application.

On the device how ever you said that you do have the fb app, and so the SSO kicks in and, at least currently, there's a problem with it. Try to uninstall the facebook application on the device or maybe just cancel the SSO, i.e.: How to disable Facebook single sign on for android - Facebook-android-sdk

Upvotes: 5

Related Questions