Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: What is the share dialog class in Facebook SDK 4.x

I'm using the code below to open Facebook share dialog with a Facebook page URL.

The problem is, when I look to the shared post on my wall via Facebook application, I find the post without the shared page cover.

While if I shared the same page via Facebook application on my wall, I find the post with the shared page cover (Which of course is much cooler).

Is there a missing parameters in the code below?

I'm using Facebook SDK 4.1.2

    FacebookDialog shareDialog = new ShareDialog(mMainActivity);
    if (ShareDialog.canShow(ShareLinkContent.class))
    {
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(aFacebookPageURL))
                .build();


        shareDialog.show(linkContent);
    }

Edit 1:

using .setImageUrl(Uri.parse(aPageCoverURL))

You can see the difference between the upper half (shared via Facebook app for mobile) and the bottom half (shared via my application).

enter image description here

Edit 2: How can I use the code below to share a Facebook page? The code below is not working and no share dialog appears, I don't know if there is a missing parameters or this code is not meant to share pages, but I'm trying.

    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "page")
            .putString("og:title", aTitle)
            .putString("og:url", aURL)
            .build();

    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType(null)
            .putObject("page", object)
            .build();

    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("page")
            .setAction(action)
            .build();

    ShareDialog.show(mMainActivity, content);
like image 279
Ashraf Alshahawy Avatar asked May 20 '15 17:05

Ashraf Alshahawy


1 Answers

From the Facebook documentation:

Links

When people share links from your app to Facebook, it includes attributes that show up in the post:

  • a contentURL, the link to be shared
  • a contentTitle that represents the title of the content in the link
  • a imageURL, the URL of thumbnail image that will appear on the post
  • a contentDescription of the content, usually 2-4 sentences

If you want to display the image you should use setImageUrl(@Nullable final Uri imageUrl):

ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(aFacebookPageURL))
                .setImageUrl(Uri.parse(imageUrl))
                .build();

This is a share from SDK:

enter image description here

This is a share directly from the app:

enter image description here

like image 76
Mattia Maestrini Avatar answered Oct 11 '22 02:10

Mattia Maestrini