Sharing photo using facebook sdk 4.2.0

2.2k Views Asked by At
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);

The below code is run. If i have facebook app in the mobile, it's share the photo successful. But if i delete the facebook app, the callbackManager return the error "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."

1

There are 1 best solutions below

5
On

You can only show this dialog if you have native facebook app installed in your device. Try the same code in a device in which facebook app is installed it will work. If you want to make a custom dialog you need to

 -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

Here's the code for posting a link to Facebook from your own interface:

  ShareApi.share(content, null);

Let me know if you need any assistance. Mark this answer accepted if this helps.