我正在尝试使用 Facebook SDK 中的 ShareDialog 共享链接(我的 Google Play 应用程序链接),但问题是当 URL 是我的应用程序的 Google Play 链接时,其他信息未正确显示...实际上它正在显示只有来自 Google Play 的链接,没有名称或描述!
代码如下:
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());
我尝试了所有方法,其他 URL 确实有效(显示名称、描述、标题等),但应用程序的 URL 无效。
有谁知道为什么 Google Play 链接不能使用文本、描述或标题?
最佳答案
实际上,如果您指定 contentUrl
(如在 4.0 中)或 link
(如您的情况),它会覆盖 name
,description
等。您不需要提供其他信息,因为 url host 有责任提供在 Facebook 时间轴上发布时应显示的详细信息.
不过,如果您想分享类似来自用户的消息
,然后是您的应用程序链接
。然后我建议使用 Graph API(我浪费了 2-3 天时间通过 ShareApi/ShareDialog 发布类似的内容,但最终只使用了 Graph API。)
使用 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();
关于android - Facebook SDK 并使用 ShareDialog 问题共享 Play Store 应用程序链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081584/