0

Above is my code but i cant find out together usage, always gives error

Cannot pass a publish or manage permission (publish_actions) to a request for read authorization

This is my Permission list

private Collection<String> permissions = new ArrayList<>();
permissions.add("public_profile");
permissions.add("email");
permissions.add("user_birthday");
permissions.add("publish_actions");

And this is login request

ParseFacebookUtils.logInWithReadPermissionsInBackground(activity, permissions, new LogInCallback() {
@Override
public void done(ParseUser parseUser, ParseException parseException) {

       if (parseUser == null) {

       } else {

       }
    }
});

How can i use this together?

Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23

3 Answers3

3

After long hours, this is solution. You must behave twice login to facebook. Once is publish and other one is read permissions. If you need public profile data , just publish permission is enough but in my case i need birthday, email, etc.. So code is below;

These are my permissions lists;

Collection<String> readPermissions = new ArrayList<>();
readPermissions.add("public_profile");
readPermissions.add("email");
readPermissions.add("user_birthday");
Collection<String> publishPermissions = new ArrayList<>();
publishPermissions.add("publish_actions");

Firstly, I should login with readpermission

ParseFacebookUtils.logInWithReadPermissionsInBackground(activity, readPermissions, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException parseException) {

            if (parseUser == null) {
                listener.onFailure(new UserCancelledFacebookLogin());
            } else {
                getPublishPermissions(parseUser);
            }
        }
    });

After this, here my "getPublishPermissions" method; FacebookRequestListener is my own listener , don't care/mind delete it.

public void getPublishPermissions(final ParseUser parseUser) {
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    // User succesfully login with all permissions
                    // After this with these json and ParseUser , you can save your user to Parse
                }
            });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,first_name,last_name,name,email,gender,birthday");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException facebookException) {

        }
    });

    LoginManager.getInstance().logInWithPublishPermissions(activity, publishPermissions);
}

that's all folks =)

happy coding to everyone

Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23
0

The error message means you should not request read and write permissions at the same time. Login with read permissions when the User enters your App, request write permission (publish_actions) only right before you post.

Use ParseFacebookUtils.logInWithPublishPermissionsInBackground for that.

That error message is already well known, take a look at some other thread about it:

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • So how can i add permission to this code (while posting) SharePhoto photo = new SharePhoto.Builder().setBitmap(bitmap).setCaption(text).build(); SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build(); – Arda Kaplan Dec 15 '15 at 13:06
  • i´ve added a link. you have to authorize again, with the publish permission, right before you want to post the photo – andyrandy Dec 15 '15 at 13:17
  • "no success" is nothing we can work with, it´s the same as "it doesn´t work" - zero information ;) – andyrandy Dec 15 '15 at 13:47
-1

You need to do a POST request instead of a GET one. See:

Sample:

  Bundle param = new Bundle();
param.putString("message", "picture caption");
param.putByteArray("picture", ImageBytes);
mAsyncRunner.request("me/photos", param, "POST", new SampleUploadListener());

this is your answer check link

Community
  • 1
  • 1
Abhinav singh
  • 1,448
  • 1
  • 14
  • 31