当我的应用尝试共享内容时,说明会显示在共享活动中,但在发布时不会显示。我经历了很多stackoverflow帖子,但没有什么能解决我的问题。
这是我的通话流程:
以下是我使用的代码
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());
}
但使用FeedDialog共享相同的工作
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();
谢谢
答案 0 :(得分:1)
来自docs(版本4.0 +)
要显示活动中链接的ShareDialog,请创建一个 onCreate方法中的ShareDialog实例:
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>() { ... }); }
然后显示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); }
答案 1 :(得分:0)
Slartibartfast的答案工作正常,直到compile 'com.facebook.android:facebook-android-sdk:4.24.0'
来自Facebook SDK版本4.25.0
setContentTitle("") setContentDescription("")
已被删除。
您必须使用setQuote("");
方法而不是setContentDescription("");
有关折旧的详细信息,请参阅:https://developers.facebook.com/docs/sharing/android