Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid showing already-authorized to app dialog in Android Facebook SDK

enter image description here

I'm getting a completely useless page when I use the Single Sign on for Facebook's Android SDK.

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

This page would destroy user experience. How can I remove this screen?

Thanks in advance.

Note: we won't see this issue If the FB app is installed in device. It will be raised only if the FB app is not available in device.

like image 658
Noundla Sandeep Avatar asked Jul 18 '13 13:07

Noundla Sandeep


People also ask

How do I disable Facebook SDK?

Select your app. Click Settings. Click the SKAdNetwork for Facebook SDK toggle to turn it on or off.

How did you integrate the Facebook SDK in Android app?

To use the Facebook SDK in an Android Studio project, add the SDK as a build dependency and import the SDK. Go to Android Studio | New Project | Minimum SDK. Select API 15: Android 4.0. 3 (IceCreamSandwich) or higher and create your new project.

On which platforms does the Facebook SDK work on?

This documentation describes how to integrate your Android app with Facebook to build engaging social apps by using the Facebook SDK for Android. To learn more about using Facebook development tools, see App Development. The current version of the Facebook SDK for Android is version 15.1.


2 Answers

I am using the latest Facebook SDK 3.6 I believe and have tested so far on HTC One & Galaxy s3 mini. This page does not display itself for me at any point. I followed the API guide here...

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

Here is the code aswell... perhaps this may help.

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);
    }
}
like image 179
Jesson Atherton Avatar answered Nov 15 '22 03:11

Jesson Atherton


Before I used this code for Facebook logout :

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

After changed to this code LoginManager.getInstance().logOut(); solved the issue.

like image 35
Sindhu E Avatar answered Nov 15 '22 04:11

Sindhu E