Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm new to android development. I've downloaded facebook sdk 3.0.1, and using the sample code to log in. The problem is, that if facebook app is installed the authentication fails. (otherwise it works just fine) after pressing the log in button I get to onActivityResult with status CLOSED_LOGIN_FAILED. of course I'm not typing the password, it's done automatically through facebook's app, and the facebook app is logged in and works properly. I couldn't find a solution.. please help me :)

this is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    instance = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    buttonLoginToFacebook = (Button) findViewById(R.id.buttonLoginToFacebook);
    tvWellcome = (TextView) findViewById(R.id.tvWellcome);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

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

    updateView();
}

@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(this, requestCode,
            resultCode, data);
    updateView();
}

@Override
protected 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()) {
        Intent intent = new Intent(this, ScreenStartPage.class);
        startActivity(intent);
    } else {
        buttonLoginToFacebook.setOnClickListener(new 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));
        updateView();
    } else {
        Session.openActiveSession(this, true, statusCallback);
    }
}


public 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();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
243 views
Welcome To Ask or Share your Answers For Others

1 Answer

Have you setup your debug key hash and full class name on Facebook's app settings dashbaord? see steps 5 and 6 in the Getting Started with the Facebook SDK for Android doc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...