简体   繁体   中英

Android App: Facebook LoginManager gives me “publish_actions” permission but app never goes through callbackManager callback( Facebook SDK 4.18.0)?

I press a custom button to let the user give publish permissions to my Android app(Facebook SDK 4.18.0). It works. It goes to the facebook fragment in which prompts the user to give publish permissions to the app and then it comes back to the activity in which the button was pressed. The thing is that I've run the debugger and it never goes through the callback functions which I need to do what I need to do after the user has accepted.

The listener:

permissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            permissionButton.startAnimation(rotation);

            JSONObject userCredentials = new JSONObject();

           //ask for facebook publishing permissions

            if(facebook_connected) {
                CallbackManager callbackManager = CallbackManager.Factory.create();

                facebookLoginWithPublishPermissions(callbackManager);
            }




        }
    });

And my custom function 'facebookLoginWithPublishPermissions' which intends to get a token with publish permissions(do I need a new one or the old one works now that I've been granted the "publish_actions" permissions for this user, cause I'm already logged in and have the access_token but only with the basic permissions using firebase ui auth module for android)? If I go to the facebook page of the user I can see that the proper permissions has been set so everything OK regarding that. The code:

private void facebookLoginWithPublishPermissions(CallbackManager callbackManager) {
        LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.d("FACEBOOK_LOGIN_RESULT", "facebook login success");
                Log.d("LOGIN_RESULT", loginResult.getAccessToken().getToken());
            }

            @Override
            public void onCancel() {
                Log.d("FACEBOOK_LOGIN_RESULT", "facebook login canceled");

            }

            @Override
            public void onError(FacebookException exception) {
                Log.e("FACEBOOK_LOGIN_RESULT", "facebook login error");
                exception.printStackTrace();
            }
        });

        LoginManager.getInstance().logInWithPublishPermissions((Activity) mContext, Arrays.asList("publish_actions"));
    }

1-How can I get a new token(in case is need to renew the token if you ask for additional permissions)? 2-How can I make the callback function work to perform actions after the publish_actions permission has been granted??

Thank you very much for your help!

EDIT: For future reference regarding Facebook API/Permission politics, Facebook provides a DIFFERENT Token from the one you are first provided when you login with the basic permissions. They have to review your app to see if you are using the permissions ONLY when you need it and also to check if you are not asking those permissions "just in case" to avoid unnecessary requests to their server. Also they want to make sure that you let the user know what's happening, they must accept the publishing permission, that's why you have to do 2 requests, first the read permissions the first time you connect to facebook, and a second request for writing(publish_actions) permissions. You CANNOT ask for publishing permissions unless you already asked for reading permissions first....

Are you adding the following method to your code ?

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
    Log.d("TAG: 5. ", "I´m at onActivity result");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM