Unable to post Facebook Open Graph Story in Android App

1.2k Views Asked by At

Firstly I am aware that there are a number of similar questions already asked so apologies for the repetition. I am endeavouring to share a custom Open Graph story to Facebook from an App I am developing using the Share Dialog approach. I have followed the documentation and also looked into existing questions for guidance but I cannot make this work.

What I see when I attempt to test the integration is the Share Dialog appears momentarily then it dismisses itself. I get the following (terrifically useful) message in the log "com.facebook.FacebookException: Failed to generate preview for user"! Try as I might I cannot get past this problem.

I have created a custom Story from the Facebook dashboard with an action of "Complete" and an object of "Puzzle". I have set an html file for the puzzle object on an external server. The code in the app is as follows:

final ArrayList<Bitmap> imageList = new ArrayList<Bitmap>();
imageList.add(image);

OpenGraphObject puzzle = OpenGraphObject.Factory.createForPost("puzzle");
puzzle.setProperty("title", title);
puzzle.setProperty("image", "http://www.example.com/app-facebook/images/icon.png");
puzzle.setProperty("url", "http://www.example.com/app-facebook/puzzle.html");
puzzle.setProperty("description", desc);

OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setType("myapp.complete");
action.setProperty("puzzle", puzzle);

FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action,
    "puzzle")
//.setImageAttachmentsForObject("puzzle", imageList)
.build();
if (FacebookDialog.canPresentOpenGraphActionDialog(getApplicationContext(),
    FacebookDialog.OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) {
    fbUiHelper.trackPendingDialogCall(shareDialog.present());
} else {
    Log.w(LOG_TAG, "fbShareStory: Cannot present");
}

Any help much appreciated.

0

There are 0 best solutions below