ShareDialog shareDialog = new ShareDialog(this);

shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                Toast.makeText(SharePage.this, "ok", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancel() {
            }

            @Override
            public void onError(FacebookException error) {
                Toast.makeText(SharePage.this, error.getMessage(), Toast.LENGTH_LONG).show();
            }
        });

SharePhoto photo = new SharePhoto.Builder().setBitmap(bm).setCaption(description).build();
SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
shareDialog.show(content);

运行以下代码。
如果我在手机里有Facebook应用,那就是成功分享照片。
但如果我删除Facebook应用程序,CallbackManager将返回错误“Unable to show the provided content via the web or the installed version of the Facebook app. Some dialogs are only supported starting API 14.

最佳答案

只有在设备中安装了本机Facebook应用程序时,才能显示此对话框。在安装了facebook应用程序的设备中尝试相同的代码,它将正常工作。
如果要创建自定义对话框,则需要

 -Build a custom interface that posts to the Graph API endpoint /me/feed
 -Implement Facebook Login in your app
 -Request the publish_actions permission when people log into your app

以下是从您自己的界面发布Facebook链接的代码:
  ShareApi.share(content, null);

如果你需要帮助,请告诉我。
如果有帮助,请将此答案标记为已接受。

关于android - 使用Facebook SDK 4.2.0共享照片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30843786/

10-12 00:32
查看更多