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,746
  • 10
  • 36
  • 56
Arda
  • 1,591
  • 1
  • 13
  • 19

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
  • 1,591
  • 1
  • 13
  • 19
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
  • 70,918
  • 8
  • 110
  • 125
  • 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 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,398
  • 1
  • 13
  • 30
  • so What is "ShareApi" ? – Arda Dec 15 '15 at 13:10
  • this is your requirement you want to publish image then in this way to publish your image in facebook.. – Abhinav singh Dec 15 '15 at 13:13
  • actually, his problem is the login process (see error message), not the upload itself. also, the link to the scores api is not really relevant... – andyrandy Dec 15 '15 at 13:14
  • I have say login through facebook not parse. because if you login through parse then facebook not provided and information to user. – Abhinav singh Dec 15 '15 at 13:15
  • if you want to login through parse then check this. http://stackoverflow.com/questions/29748256/parse-login-through-facebook-api-4-0-in-android-studio/29865703#29865703 – Abhinav singh Dec 15 '15 at 13:18
  • I use Parse login for Facebook Login than i get informations from facebook graph api request. – Arda Dec 15 '15 at 13:30