根据此链接,我已安装SDK 3.2.1并实现了uiHelper,以及FacebookDialog,如下所示:
现在,即使在手机上安装了Facebook应用程序并调用publishFeedDialog(),FacebookDialog.canPresentShareDialog始终为false。但是此后应用程序崩溃。
有什么解决方法吗?如果我的手机中有应用程序,为什么会显示正常的Facebook对话框?(我使用的是Lenevo型号,如果有帮助的话)
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
Toast.makeText(this, "if", Toast.LENGTH_LONG).show();
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
this).setLink("https://developers.facebook.com/android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Toast.makeText(this, "else", Toast.LENGTH_LONG).show();
// Fallback. For example, publish the post using the Feed Dialog
publishFeedDialog();
}
对于publishFeedDialog()
,我的建议是:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption",
"Build great social apps and get more installs.");
params.putString(
"description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(),
"Posted story, id: " + postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story", Toast.LENGTH_SHORT)
.show();
}
}
}).build();
feedDialog.show();
}
现在,即使在手机上安装了Facebook应用程序并调用publishFeedDialog(),FacebookDialog.canPresentShareDialog始终为false。但是此后应用程序崩溃。
有什么解决方法吗?如果我的手机中有应用程序,为什么会显示正常的Facebook对话框?(我使用的是Lenevo型号,如果有帮助的话)
但是
当我点击分享按钮时,Facebook会弹出一个通知,上面写着“出了点问题,请重试”。 - Sarthak Majithia