4

I have this simple problem made complicated because of FB. I try to share from android a link and image using facebook sdk. Did anyone played with ShareOpenGraphObject, ShareOpenGraphAction and ShareOpenGraphContent before, facebook documentation just sucks, no examples at all. I am waiting for examples.

Thanks

3
  • Personally I have not. I am sure a lot of people are willing to help, but you have to show some code. Aug 12, 2015 at 10:18
  • 1
    I am pretty sure FB documentation is good enough. If you need help you should post some code what you have tried so far.
    – Rohit5k2
    Aug 12, 2015 at 10:20
  • let s post some code then: Aug 12, 2015 at 10:37

4 Answers 4

2

let s post some code then:

    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "books.book")
            .putString("og:title", "A Game of Thrones")
            .putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
            .putString("books:isbn", "0-553-57340-3")
            .build();

    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("books.reads")
            .putObject("book", object)
            .putPhoto("image", photo)
            .build();

    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("book")
            .setAction(action)
            .build();

    shareDialog.show(this, content);

idea is that i don t want to use a book, i just want so share a image a link and a message...how the f i do that? facebook sdk sucks

0

Its Simple, You can find many examples as well as in Facebook SDK you can find sample for the same...

Bundle postParams = new Bundle();           
postParams.putString("link", url);
postParams.putString("picture", imgUrl);

    Request request = new Request(session, "me/feed", postParams, 
                    HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
1
  • not simple at all, fb docs sucks, and i want to create a content and display it so users can edit. thanks Aug 12, 2015 at 10:37
0

I think by using facebook sdk 4.0, you can share contents via share api.

eg:

public void share()
{
ShareLinkContent content=new ShareLinkContent.Builder()
.setContentTitle("Your Title")
.setContentUrl(Uri.parse("website link"))
.setImageUrl(Uri.parse("Image url"))
.build();

ShareApi.share(content, new FacebookCallback<Sharer.Result>(){
@Override
public void onSuccess(Result result){

}
@Override
public void onCancel(){

}
@Override
public void onError(FacebookException error){

}
});
}
5
  • could be a solution, but it isnt :D, i have to share a local picture, not one from a link Aug 12, 2015 at 11:10
  • You can share local images using sharePhoto class, which is specified in facebook sdk document.
    – userDroid
    Aug 12, 2015 at 11:18
  • i know i can use sharePhoto, but also i need to attach a link and a comment to the Photo...do u know how can i do that? Aug 12, 2015 at 11:19
  • SharePhotoContent Class provide an option to add sharephoto and ContentUrl. But, i am not sure it is worked.
    – userDroid
    Aug 12, 2015 at 11:23
  • not working, content url only works to upload a pic from a url, nothing more Aug 12, 2015 at 11:57
0

For sharing link and image , ShareDialog Provides functionality to share content via the Facebook Share Dialog and

ShareLinkContent Describes link content to be shared.

is one method without the Open Graph method.

Snippet is like

private ShareDialog shareDialog;
private boolean canPresentShareDialogWith;

shareDialog = new ShareDialog(this);

canPresentShareDialogWith = ShareDialog.canShow(ShareLinkContent.class);


ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentTitle("Shared from " + "<APP NAME>")
                            .setContentDescription(
                                    "Question:" + data.getQuestion() + "\n"
                            // + "Asked by : "
                            // + data.getName() + "\n"
                            )
                            .setContentUrl(
                                    Uri.parse("<Website url>"))
                            .setImageUrl(Uri.parse(data.getPicUploadPath()))
                            .build();

                    if (canPresentShareDialogWith) {
                        shareDialog.show(linkContent);
                    } else if (profile != null && hasPublishPermission()) {
                        ShareApi.share(linkContent, shareCallback);
                    }


private FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>() {
    @Override
    public void onCancel() {
        Log.d("HelloFacebook", "Canceled");
    }

    @Override
    public void onError(FacebookException error) {
        Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
        String title = getString(R.string.error);
        String alertMessage = error.getMessage();
        showResult(title, alertMessage);
    }

    @Override
    public void onSuccess(Sharer.Result result) {
        Log.d("HelloFacebook", "Success!");
        if (result.getPostId() != null) {
            String title = getString(R.string.success);
            String id = result.getPostId();
            String alertMessage = getString(
                    R.string.successfully_posted_post, id);
            showResult(title, alertMessage);
        }
    }

    private void showResult(String title, String alertMessage) {
        new AlertDialog.Builder(NewsfeedMain.this).setTitle(title)
                .setMessage(alertMessage)
                .setPositiveButton(R.string.ok, null).show();
    }
};

The method here is sharing a link with the respective web url to load , when clicked from FB feed and the image shared is via a link by the native facebook android app or fallback to sdk share dialog is no facebook app is persent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.