简体   繁体   English

Facebook身份验证无法在Android手机上运行

[英]Facebook Authentication is not working on Android Phone

I have made an android application in which I need to login using Facebook and as soon as authentication is successful, I need to go to another intent. 我已经制作了一个Android应用程序,我需要使用Facebook登录,一旦身份验证成功,我需要转到另一个意图。 So I downloaded Facebook Android SDK from here . 所以我从这里下载了Facebook Android SDK。

After download and importing into eclipse I extended the SessionLoginExample from that SDK. 下载并导入到eclipse后,我从该SDK扩展了SessionLoginExample In my emulator it is working fine for me, I am able to login to Facebook Application using that and also as soon as I am logged in, it is going to another Intent as well. 在我的模拟器中,它对我来说很好,我可以使用它登录到Facebook应用程序,并且一旦我登录,它也将转到另一个Intent。

Problem Statement:- 问题陈述:-

But the problem arises after I installed the application on the real Android Phone. 但是在我在真正的Android手机上安装应用程序后出现问题。 After installing it on the Android phone, as soon as it open the Facebook login page, after putting my username and password into that, it is not going to another intent and after sometime I am getting an exception in my console as well. 在Android手机上安装后,只要打开Facebook登录页面,在输入我的用户名和密码之后,它就不会出现另一个意图,过了一段时间我也会在我的控制台中出现异常。 And after that every time I get a message Facebook has stopped working and then I get message my Application has forced closed . 之后,每次我收到消息Facebook has stopped working ,然后我收到消息,我的Application has forced closed

One more thing I have noticed is- As soon as I open my application in Android Phone, I always get message in my console saying that Login Failed without even I have entered my username and password in to Facebook page. 我注意到的另一件事是 - 一旦我在Android手机中打开我的应用程序,我总是在我的控制台中收到消息,说明Login Failed ,甚至没有输入我的用户名和密码进入Facebook页面。

Below is the code I am using from SessionLoginExample - 以下是我在SessionLoginExample使用的代码 -

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment, container, false);

    buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout);
    textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
        session = Session.restoreSession(getActivity(), null, statusCallback,
            savedInstanceState);
        }
        if (session == null) {
        session = new Session(getActivity());
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }

    updateView();

    return view;
    }

    @Override
    public void onStart() {
    super.onStart();
    Session.getActiveSession().addCallback(statusCallback);
    }

    @Override
    public void onStop() {
    super.onStop();
    Session.getActiveSession().removeCallback(statusCallback);
    }

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

    @Override
    public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Session session = Session.getActiveSession();
    Session.saveSession(session, outState);
    }

    private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {

    // After login is successful, I am going to another Intent
        Intent thesisProject = new Intent(getActivity(), ThesisProjectAndroid.class);
        startActivity(thesisProject);

    } else {
        Log.d(TAG_LOGIN_FAILED,
            "There is something wrong with your Facebook account. Please try again.");

        textInstructionsOrLink.setText(R.string.instructions);
        buttonLoginLogout.setText(R.string.login);
        buttonLoginLogout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickLogin();
        }
        });
    }
    }



    private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(getActivity(), this, true, statusCallback);
    }
    }

    private void onClickLogout() {
    Session session = Session.getActiveSession();
    if (!session.isClosed()) {
        session.closeAndClearTokenInformation();
    }
    }

    private class SessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        updateView();
    }
    }
}

And I get below exception as well- 我也得到以下例外 -

01-30 11:06:08.400: E/AndroidRuntime(7463): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.facebook.samples.sessionlogin/com.facebook.LoginActivity}: java.lang.NullPointerException

Can anyone help me out with this why it is happening to my Phone? 任何人都可以帮我解决这个问题,为什么它会发生在我的手机上?

From my experience, you can solve the Exception you show by checking the resultCode in onActivityResult, before you pass it up to the Session, eg: 根据我的经验,您可以通过检查onActivityResult中的resultCode来解决您显示的异常,然后再将其传递给Session,例如:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (Session.getActiveSession() != null && resultCode == RESULT_OK) {
Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
}
}

Can't help you with the original problem though, of your facebook login not working, sorry. 不能帮你解决原来的问题,你的facebook登录不起作用,抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM