Search code examples
androidfacebookfacebook-android-sdkandroid-simple-facebook

android simple facebook returning "cancelled by user" when trying to share a post


I have downloaded and setup the android simple facebook sdk from github. I have made a simple page to test publishing a feed, and I was able to get to the point where I can add a message and click "share". However, once I click share, a progress dialog comes up that says "sending..." and then it goes away but nothing is sent. I printed the error message and it just says "Cancelled by user".

Here is the code I have, its just a button that logs in, and on success tries to post a feed.

Button postStuff;
private UiLifecycleHelper uiHelper;

Permission[] permissions = new Permission[] {
        Permission.USER_PHOTOS,
        Permission.EMAIL,
        Permission.PUBLISH_ACTION
    };
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
    .setAppId("My-App-ID")
    .setNamespace("my_namespace")
    .setPermissions(permissions)
    .build();
SimpleFacebook mSimpleFacebook;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.fbtest);

    SimpleFacebook.setConfiguration(configuration);

    postStuff = (Button) findViewById(R.id.postStuff);

    postStuff.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            OnLoginListener onLoginListener = new OnLoginListener() {
                @Override
                public void onLogin() {
                    // change the state of the button or do whatever you want
                    Log.i("fb login", "Logged in");

                    OnPublishListener onPublishListener = new OnPublishListener() {
                        @Override
                        public void onComplete(String postId) {
                            Log.i("fb post", "Published successfully. The new post id = " + postId);
                        }

                        @Override
                        public void onFail(String reason) {
                            Log.i("fb post","failed: " + reason);
                        }

                        /* 
                         * You can override other methods here: 
                         * onThinking(), onFail(String reason), onException(Throwable throwable)
                         */
                    };
                    Feed feed = new Feed.Builder()
                    .setMessage("Check this out.")
                    .setName("Home Shop Guide App for Android")
                    .setCaption("Win prizes and deals daily")
                    .setDescription("User just won $500 from a daily scratchoff prize. You could be the next winner!")
                    .setPicture("https://homeshopguide.com/images/logo.png")
                    .setLink("https://homeshopguide.com/")
                    .build();
                    mSimpleFacebook.publish(feed, true, onPublishListener);
                }

                @Override
                public void onNotAcceptingPermissions(Permission.Type type) {
                    // user didn't accept READ or WRITE permission
                    Log.w("fb login", String.format("You didn't accept %s permissions", type.name()));
                }

                @Override
                public void onThinking() {
                    // TODO Auto-generated method stub
                    Log.i("fb login", "thinking");
                }

                @Override
                public void onException(Throwable throwable) {
                    // TODO Auto-generated method stub
                    Log.i("fb login", "exception" + throwable.getLocalizedMessage());
                }

                @Override
                public void onFail(String reason) {
                    // TODO Auto-generated method stub
                    Log.i("fb login", "failed: " + reason);
                }

            };
            mSimpleFacebook.login(onLoginListener);

        }

    });


}

@Override
public void onResume() {
    super.onResume();
    mSimpleFacebook = SimpleFacebook.getInstance(this);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data); 
    super.onActivityResult(requestCode, resultCode, data);
} 

And this is what shows up in the error log when i press the button:

03-19 17:01:53.537: I/fb login(31226): Logged in
03-19 17:01:53.647: D/OpenGLRenderer(31226): Flushing caches (mode 1)
03-19 17:01:53.957: D/OpenGLRenderer(31226): Flushing caches (mode 0)
03-19 17:02:05.527: I/fb post(31226): failed: Canceled by user

EDIT: I tried again the next day (before making any changes) and the log showed that the post was successful. However, the facebook account I am using to develop with is a business account and I do not know where the feed got posted to.

As sromku suggested I put the app in live mode to test with a normal facebook account. I am still receiving the "Canceled by user" error. however, when I checked my wall the post was there as expected. My question now is am I doing something wrong to receive this error or is it just an error showing up when it is not supposed to.


Solution

  • This behaviour has been fixed in simple facebook 2.2 release. I've been experiencing the same issue and it got fixed after updating the lib. Check this issue for the details.