Facebook SDK and sharing a Play Store app link with ShareDialog issue

隐身守侯 提交于 2019-12-03 17:26:44

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!