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

廉价感情. 提交于 2019-12-01 01:44:39

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/10249889/logging-in-to-facebook-from-my-app-works-on-emulator-but-not-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!