android facebook loginbutton自动登录

时间:2013-07-30 10:31:11

标签: android facebook facebook-graph-api android-facebook facebook-sdk-3.0

我想使用facebook登录按钮但不通常它会自动登录,我想让它自动退出并且用户按下它然后登录过程开始,我知道它是自动登录因为我登录了我的机器人facebook应用程序。

代码/ H3>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.facebook.widget.LoginButton
        android:id="@+id/authButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        />

</LinearLayout>

2 个答案:

答案 0 :(得分:2)

实际上,如果我正确地理解了这个问题,那么你想要与穆罕默德·阿米尔里所发布的相反。应该是这样的:

OnCreate方法中的

    Session activeSession = Session.getActiveSession();
    //Checks for an open session
    if (!(activeSession == null || activeSession.getState().isClosed())) {
        //if found one, kill it. 
        activeSession.closeAndClearTokenInformation();
    }
    LoginButton authButton = (LoginButton) layout.findViewById(R.id.authButton);
    authButton.setReadPermissions(Arrays.asList("basic_info", "email"));

如果有人知道更好的方法来完成同样的事情,我非常想知道(因为我现在面对这个问题)。比如,如何防止Facebook在创建按钮时检查打开的会话。

答案 1 :(得分:0)

In onCreate method.


        Session activeSession = Session.getActiveSession();
        if (activeSession == null || activeSession.getState().isClosed()) {
            activeSession = new Session.Builder(context).setApplicationId(context.getString(R.string.app_id)).build();
            activieSession = Session.setActiveSession(activeSession);
        }
        Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

        LoginButton login = (LoginButton)findViewById(R.id.login);
        login.setReadPermissions(Arrays.asList("user_groups", "user_photos"));


@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user
    // session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    Session session = Session.getActiveSession();
    if (session != null && (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }
    uiHelper.onResume();
}

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