Facebook SDK 4.0 LoginButton - setReadPermissions not working?

I have implemented LoginButton from Facebook 4.0 SDK. Input and output are working normally.

Now I want to set permission "user_friends" with LoginButton.setReadPermissions(Arrays.asList("user_friends"));

But it looks like this line of code is being ignored? When I read the permissions after successfully logging in with getAccessToken().getPermissions();

, I only have "basic_info" .

If I use LoginManager.getInstance().logInWithReadPermissions( HighscoreFragment.this, Arrays.asList("user_friends") );

this instead, I get the correct permissions. But I want to use LoginButton .

So what is the correct way to implement the LoginButton and set the required permissions on login?

This is my code:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_highscore, container, false);

        mLoginButton = (LoginButton) view.findViewById(R.id.login_button);
        mLoginButton.setReadPermissions(Arrays.asList("user_friends"));
        mLoginButton.setFragment(this);    

        // Callback registration
        mLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                Log.i(TAG, "LOGIN SUCCESFUL");
                Log.i(TAG, loginResult.getAccessToken().getPermissions().toString());
                AccessToken accessToken = AccessToken.getCurrentAccessToken();
                if (accessToken != null) {
                    if(accessToken.getPermissions().contains("user_friends"))
                        fetchScoreboardEntries();
                }
            }

            @Override
            public void onCancel() {
                Log.i(TAG, "LOGIN CANCEL");
            }

            @Override
            public void onError(FacebookException exception) {
                Log.i(TAG, "LOGIN ERROR");
            }
        });

      

+3


source to share


1 answer


I think your problem is this:

  • You started with an open LoginButton (only asking for permission basic_info

    )
  • You have tested the login and received a valid access token
  • You changed your code to request user_friends

    using LoginButton
  • Now you cannot get additional permissions with LoginButton


I have identified this as a bug in the SDK and we will fix it in an upcoming release.

The current work during development is to de-authorize your app (from your Facebook settings) when you make changes to the LoginButton. So this will invalidate your access token and the next time you log in, you should see a user_friends

permission dialog in the box. This should only be a problem if you make changes to the permission array between app updates.

+6


source







All Articles