Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook Share not showing description on facebook wall

When my app try to share something, the description is shown in the share activity, but it does not show up when it is posted. I went through many stackoverflow posts, but nothing could solve my problem.

Here is my call flow :

  1. Share button is clicked
  2. Activity calls a static method and passes itself and content to share to it via Bundle
  3. Share activity is invoked from this static method. It displays the content to share correctly with all image, caption and description
  4. Content is shared successfully
  5. When the facebook post is checked, it just shows the playstore app details, with the image that I had set in 3, without the description

Here is the code that i use

if (FacebookDialog.canPresentShareDialog(activity.getApplicationContext(), 
     FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) 
    {
     FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(activity)
           .setLink("<playstore link>")
           .setApplicationName("<appname>")
           .setName("<some name>")
           .setCaption("<some text>")
           .setDescription("a description")
           .setPicture("http://url/to/image.jpg")
           .build();
        uiHelper.trackPendingDialogCall(shareDialog.present());
    }

But sharing the same using FeedDialog works

Bundle params = new Bundle();
                    params.putString("name", "name");
                    params.putString("caption", "caption");
                    params.putString("description","desc");
                    params.putString("link", "playstore link");
                    params.putString("picture", "http://url/to/image.jpg");

                    WebDialog feedDialog = (
                        new WebDialog.FeedDialogBuilder(activity,
                                session,
                            params))
                        .setOnCompleteListener(new OnCompleteListener() {

                            @Override
                            public void onComplete(Bundle values,
                                FacebookException error) {
                                if (error == null) {

                                    final String postId = values.getString("post_id");
                                    if (postId != null) {
                                        Toast.makeText(activity,

                                            "Posted Successfully!",
                                            Toast.LENGTH_SHORT).show();
                                        activity.finish();
                                    } else {
                                        // User clicked the Cancel button
                                        Toast.makeText(activity.getApplicationContext(), 
                                            "Publish cancelled", 
                                            Toast.LENGTH_SHORT).show();

                                        activity.finish();
                                    }
                                } else if (error instanceof FacebookOperationCanceledException) {
                                    // User clicked the "x" button
                                    Toast.makeText(activity.getApplicationContext(), 
                                        "Publish cancelled", 
                                        Toast.LENGTH_SHORT).show();
                                    activity.finish();
                                } else {

                                    Toast.makeText(activity.getApplicationContext(), 
                                        "An Error Occurred", 
                                        Toast.LENGTH_SHORT).show();
                                    activity.finish();
                                }


                            }



                        })
                        .build();
                    feedDialog.show();

Thank You

like image 234
Sachin Murali G Avatar asked Oct 31 '22 10:10

Sachin Murali G


1 Answers

From the docs (Versions 4.0+)

To show the ShareDialog for a link in your activity, create a ShareDialog instance in your onCreate method:

public class MainActivity extends FragmentActivity {
    CallbackManager callbackManager;
    ShareDialog shareDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);
        // this part is optional
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
    }

Then show the ShareDialog:

if (ShareDialog.canShow(ShareLinkContent.class)) {
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("Hello Facebook")
            .setContentDescription(
                    "The 'Hello Facebook' sample  showcases simple Facebook integration")
            .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
            .build();

    shareDialog.show(linkContent);
}
like image 120
Vrashabh Irde Avatar answered Nov 11 '22 10:11

Vrashabh Irde