0

I am working in project that needs to publish some articles , I am struggle to find way to publish some text without permission but I fail then I decided to grant publish_actions , I stuck with this error

You need to test this permission in your app with any account listed in Roles before you can submit for review. It looks like you haven't tested this permission because no API request has been made against publish_actions in the last 30 days.

enter image description here

after search I find I must test this permission before grant it

List<String> mReadPermissions = Arrays.asList("email", "public_profile", "user_friends");
    List<String> mPublishPermissions = Arrays.asList("publish_actions");

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate");
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();


          _loginfb.setReadPermissions(mReadPermissions);
        _loginfb.setPublishPermissions(mPublishPermissions);
        _loginfb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                final Bundle params = new Bundle();
                params.putString("fields", "id, email, name, picture.type(large)");

                System.out.println("Success callback");
                GraphRequest mRequest = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject json, GraphResponse response) {
                                if (response.getError() != null) {
                                    // handle error
                                    Log.i(TAG, "ERROR");
                                } else {
                                    Log.i(TAG, "Success");
                                    String jsonresult = String.valueOf(json);
                                    Log.i("JSON Result", jsonresult);

                                    LoginWithFB(json);
                                }
                            }
                        });
                mRequest.setParameters(params);
                mRequest.executeAsync();

            }

            @Override
            public void onCancel() {

            }
        @Override
        public void onError(FacebookException error) {

        }
    });

But I got this error

Cannot call setPublishPermissions after setReadPermissions has been called.

any one can guide me how to grant steps I am using facebook sdk 4

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156

1 Answers1

1

As mentioned in facebook docs you can't use publishPermission with readPermission Facebook dev doc

According to the doc's

The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.

so after Successfull login and getting response from Graph api call loginbutton.clearPermissions(); to set PublishPermission

Code :

_loginfb=(LoginButton)findViewById(R.id.fblogin);

    _loginfb.setReadPermissions(mReadPermissions);

    _loginfb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            final Bundle params = new Bundle();
            params.putString("fields", "id, email, name, picture.type(large)");

            System.out.println("Success callback");
            GraphRequest mRequest = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject json, GraphResponse response) {
                            _loginfb.clearPermissions();
                            _loginfb.setPublishPermissions(mPublishPermissions);
                            if (response.getError() != null) {
                                // handle error

                            } else {

                                String jsonresult = String.valueOf(json);



                            }
                        }
                    });
            mRequest.setParameters(params);
            mRequest.executeAsync();

        }

        @Override
        public void onCancel() {

        }


    @Override
    public void onError(FacebookException error) {
        // TODO Auto-generated method stub
        System.out.println(error);
    }
});
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • I need ask for publish permission on publish article only but I cant could you have snap code doing this function – Mina Fawzy Feb 03 '16 at 09:24
  • 1
    @MinaFawzy please check my updated answer, call `clearPermissions()` to set `PublishPermissions` after successful login and getting user info in response i.e. in `onCompleted` – Kapil Rajput Feb 03 '16 at 09:49
  • thanks man , this solve my problem but I still have this red alert – Mina Fawzy Feb 03 '16 at 10:20
  • u'r welcome , do publish any post from your app by login from an account as mentioned in **Roles** ,go through this link for clarity https://developers.facebook.com/docs/facebook-login/review/how-to-submit#testpermissions – Kapil Rajput Feb 03 '16 at 10:28
  • thanks mate , please share example code of how can I publish any text to wall if you can – Mina Fawzy Feb 03 '16 at 10:31
  • use `ShareDialog` to share on wall , check my answer here http://stackoverflow.com/questions/34651882/facebook-share-from-my-app/34652223#34652223 – Kapil Rajput Feb 03 '16 at 10:43