Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post Id facebook share dialog always return null in Android

I used test app id and log on by test user create at dash_board app on facebook develop site, require pulish_actions permission when login using login button widget of facebook sdk but result get postid always = null. Here is my code:

....

shareDialog = new ShareDialog(MainActivity.this);
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                if (result.getPostId() != null)
                    Log.e(TAG, result.getPostId());
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {

        }
    });

    pulishButton.setOnClickListener(this);
    try{
        loginButton.setPublishPermissions(new String[]{"publish_actions","publish_stream"});
    }catch (FacebookException e){
        e.printStackTrace();
    }

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.e(TAG, "success");
            loginButton.setEnabled(false);
            pulishButton.setEnabled(true);
            GraphRequest.newMeRequest(
                    loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject json, GraphResponse response) {
                            if (response.getError() != null) {
                                // handle error
                                System.out.println("ERROR");
                            } else {
                                System.out.println("Success");


                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                    }).executeAsync();
        }

        @Override
        public void onCancel() {
            Log.e(TAG, "On cancel");
        }

        @Override
        public void onError(FacebookException e) {
            Log.d(TAG, e.toString());
        }
    });
like image 913
Minh Dương Văn Avatar asked Sep 09 '15 04:09

Minh Dương Văn


2 Answers

The solution is to force ShareDialog to use Feed mode and avoid using FB's App for sharing:

shareDialog.show(linkContent, ShareDialog.Mode.FEED);

I believe this is a bug by FB. They don't send postId to onSuccess callback when using FB App for sharing (postId = null), but they do if you use Feed.

I've heard you can avoid the "postId=null" problem by using Facebook Login and demanding "publish_actions" permission. But I don't think this is the correct way to deal with this problem. Regarding the mentioned permission Facebook states:

Publishing via dialogs or social plugins does not require this permission. Do not request review of this permission if you're only using Share dialog, Feed Dialog, Message Dialog etc, or Social Plugins (e.g. the Like Button.)

Facebook's docs on Share Dialog:

This does not require Facebook Login or any extended permissions, so it is the easiest way to enable sharing on the web.

like image 192
John Binary Avatar answered Oct 16 '22 10:10

John Binary


Facebook confirmed this issue in their latest update: https://developers.facebook.com/support/bugs/478167629274681/ https://developers.facebook.com/support/bugs/647119912303459/

like image 29
wyznr wyznr Avatar answered Oct 16 '22 09:10

wyznr wyznr