8

在此处输入图像描述

当我为 Facebook 的 Android SDK 使用单点登录时,我得到了一个完全无用的页面。

"You have already authorized app. Press "Okay" to continue.

这个页面会破坏用户体验。我怎样才能删除这个屏幕?

提前致谢。

注意:如果设备中安装了 FB 应用程序,我们不会看到此问题。仅当 FB 应用程序在设备中不可用时才会引发。

4

2 回答 2

1

我正在使用Facebook SDK 3.6我认为的最新版本,并且到目前为止已经在HTC OneGalaxy s3 mini上进行了测试。此页面在任何时候都不会为我显示。我在这里遵循了 API 指南...

https://developers.facebook.com/docs/facebook-login

这也是代码......也许这可能会有所帮助。

public class LoginHandlerFrag extends Fragment {

    private UiLifecycleHelper uiHelper;
    private static final String TAG = "HomeFragment";
    // private ProfilePictureView profilePictureView;

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                         Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

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

        LoginButton authButton = (LoginButton) view
                .findViewById(R.id.authButton);

        authButton.setReadPermissions(Arrays.asList("email", "user_location",
                "user_birthday", "user_likes", "user_photos"));
        authButton.setFragment(this);

        Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

        return view;
    }

    private void makeMeRequest(final Session session) {
        // Make an API call to get user data and define a
        // new callback to handle the response.
        Request request = Request.newMeRequest(session,
                new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {

                        // If the response is successful
                        if (session == Session.getActiveSession()) {
                            if (user != null) {
                                // profilePictureView.setProfileId(user.getId());
                            }
                        }
                        if (response.getError() != null) {
                            // Handle errors, will do so later.
                        }
                    }
                });
        request.executeAsync();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        uiHelper = new UiLifecycleHelper(getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);
    }

    private void onSessionStateChange(Session session, SessionState state,
                                      Exception exception) {
        session = Session.getActiveSession();
        SharedPreferences storedPrefs = PreferenceManager
                .getDefaultSharedPreferences(getActivity().getApplicationContext());
        SharedPreferences.Editor editor = storedPrefs.edit();
        editor.putBoolean("userLoggedTracker", true);
        editor.commit();

        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");
            makeMeRequest(session);
            editor.putBoolean("userLoggedTracker", false);
            editor.commit();
            getView().setVisibility(View.GONE);

        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
            editor.putBoolean("userLoggedTracker", true);
            editor.commit();
            getView().setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();

        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);
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }
}
于 2014-02-04T11:46:09.727 回答
1

在我将此代码用于 Facebook 注销之前:

if (AccessToken.getCurrentAccessToken() == null) {
            return; // already logged out
        }

        new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
                .Callback() {
            @Override
            public void onCompleted(GraphResponse graphResponse) {

                LoginManager.getInstance().logOut();

            }
        }).executeAsync();

更改为此代码后LoginManager.getInstance().logOut();解决了该问题。

于 2016-08-23T09:30:35.157 回答