1

我想使用 facebook loginbutton 但不幸的是它会自动登录,我想让它自动注销并用户按下它然后登录过程开始,我知道它是自动登录的,因为我在我的 android 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>
4

2 回答 2

2

实际上,如果我正确理解了这个问题,那么您想要的与 MuhammadAamirALi 发布的内容相反。应该是这样的:

在 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 在创建按钮时检查打开的会话。

于 2013-12-12T12:48:57.540 回答
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);
}
于 2013-07-30T10:59:37.363 回答