4
votes

I'm trying to share a link(my Google Play app link) using ShareDialog from Facebook SDK but the problem is that when the URL is my app's Google Play link the other information is not displayed correctly... Actually it's displaying only the link from Google Play without name or description!

Here's the code:

FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
                    this)
                    .setLink("https://play.google.com/store/apps/details?id=<myapp>")
                    .setDescription("Test")
                    .setName("Test for facebook")                       
                    .build();
            uiHelper.trackPendingDialogCall(shareDialog.present());

I tried everything and with other URL's actually is working(displaying name, description, caption etc.) but not with the app's URL.

Does anyone know why a Google Play link won't work with text, description or caption?

1

1 Answers

4
votes

Actually if you specify the contentUrl (as in 4.0) or link (as in your case), it overrides the name, description, etc. You just don't need to give other things as it then becomes responsibility of url host to supply the details that should be shown when it gets posted on Facebook timeline.

Although, if you want to share something like Message from user followed by your app link. Then I would suggest to go for Graph API (I wasted 2-3 days in posting something like this via ShareApi/ShareDialog but ended up with using Graph API only.)

Code to share using Graph API:

// Constants to be used when sharing message on facebook time line.
private static final int FACEBOOK_ERROR_PERMISSION = 200;
private static final String PARAM_EXPLICIT = "fb:explicitly_shared";
private static final String PARAM_GRAPH_PATH = "/me/feed";
private static final String PARAM_MSG = "message";
private static final String PARAM_LINK = "link";

// Create the parameter for share.
final Bundle params = new Bundle();
params.putBoolean(PARAM_EXPLICIT, true);
params.putString(PARAM_LINK, BirdingUtah.APP_URL);

// If message is empty, only our link gets posted.
String message = "This is the message to share";
if (!TextUtils.isEmpty(message))
    params.putString(PARAM_MSG, message);

// Send the request via Graph API of facebook to post message on time line.
new GraphRequest(AccessToken.getCurrentAccessToken(), PARAM_GRAPH_PATH,
        params, HttpMethod.POST, new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse graphResponse) {
        searchDialog.dismiss();

        if (graphResponse.getError() == null) {
            // Success in posting on time line.
            Logger.toastShort(R.string.msg_share_success);
            Logger.debug(TAG, "Success: " + graphResponse);
        } else {
            FacebookRequestError error = graphResponse.getError();
            if (error.getErrorCode() == FACEBOOK_ERROR_PERMISSION)
                // Cancelled while asking permission, show msg
                Logger.toastLong(R.string.msg_share_permission);
            else
                // Error occurred while posting message.
                Logger.toastShort(R.string.msg_share_error);
            Logger.error(TAG, "Error: " + error);
        }

        // Enable the button back again if profile and access token are non null.
        if (Profile.getCurrentProfile() != null || AccessToken.getCurrentAccessToken() != null)
            mShareButton.setEnabled(true);
    }
}).executeAsync();