Facebook share dialog PostId is null
Asked Answered
H

2

6

I am sharing a video on FB via share dialog in Android. The sharing works perfectly fine. However, FB post id returns null. The callback returns even before the video is uploaded. Please let me know, if I missing something. Below is my code.

public class TestFragment extends Fragment {

    private CallbackManager callbackManager;
    private ShareDialog shareDialog;

    public TestFragment() {
        // Required empty public constructor
    }

    public static TestFragment newInstance(String path, String json) {
        TestFragment fragment = new TestFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        FacebookSdk.sdkInitialize(getActivity());
        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);
        // this part is optional
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                Timber.d("result.getPostId() :: " + result.getPostId());
            }

            @Override
            public void onCancel() {
                Timber.d("Facebook : Cancelled");
            }

            @Override
            public void onError(FacebookException e) {
                Timber.d(e.getMessage());
            }
        });
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_test, container, false);
        ButterKnife.inject(this, view);
        return view;
    }

    @OnClick(R.id.facebookShare)
    public void share() {
        Timber.d("share button pressed");
        if (ShareDialog.canShow(ShareVideoContent.class)) {
            Timber.d("showing share dialog");
            shareDialog.show(getVideoContent());
        } else {
            Timber.d("unable to show the share dialog");
        }
    }

    private ShareVideoContent getVideoContent() {
        Timber.d(mVideoMetadata.getVideoId());

        ShareVideo shareVideo = new ShareVideo.Builder()
                .setLocalUrl(Uri.parse("... file ..."))
                .build();
        ShareVideoContent content = new ShareVideoContent.Builder()
                .setVideo(shareVideo)
                .build();

        return content;
    }

    @Override
    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
}
Hypothermal answered 7/8, 2015 at 15:49 Comment(6)
Facing the same problem at presentArgo
A post ID will only be returned if your app implements Facebook Login and requests the 'publish_actions' permission. Is this requested by your app?Arevalo
@Arevalo Thanks for this pointer. At this moment, I haven't implemented FB login. I will update once, I implement FB login.Hypothermal
mukeikh, have u solved the problem?Conjunctivitis
it requires FB login before accessing the feature.Hypothermal
hello, I used FB login before posted and still couldn't get postID. is there any other thing that you added?Breakup
A
0

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

Set mode to ShareDialog.Mode.FEED.
It's working for me .

Here's example

Ahron answered 14/3, 2017 at 8:15 Comment(0)
R
0

When Login Success With Facebook Then Call This Method shareOnFacebook()

private void shareOnFacebook(){

    ShareLinkContent shareContent = new ShareLinkContent.Builder()
            .setContentTitle("The Simpson!")
            .setContentUrl(Uri.parse("http://www.codecube.in/airbucks-project"))
            .build();

    mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);

    mFacebookShareDialog.registerCallback( this.callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {
            Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
            String postID = result.getPostId();
            Log.v("MyApp", "Share success!" +result.getPostId());                        
        }
        @Override
        public void onCancel() {
            Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
        }

        @Override
        public void onError(FacebookException e) {
            Log.v("MyApp","Share error: " + e.toString());
        }    
    });
    mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
}


@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
Rentier answered 31/5, 2017 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.