Reputation: 3016
I am using facebook SDK 4. and the open graph stories api. I am able to create an action and share it when there is no user created image, but when adding an image, I can't figure out how to link the SharePhotoContent to the action created.
My code is:
ShareOpenGraphAction.Builder actionBuilder = new ShareOpenGraphAction.Builder();
actionBuilder.setActionType("fbclimbmystats:on_sight"); //name space needed
actionBuilder.putObject("route", fbRoute);
ShareOpenGraphAction action = actionBuilder.build();
//Create a Bitmap image to add
Bitmap bitmap = null;
if (photoPath != null){
bitmap = BitmapFactory.decodeFile(photoPath);
}
SharePhoto photo = null;
if (bitmap != null){
photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.setUserGenerated(true)
.build();
}
ShareContent content;
if (photo!=null){
content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
}
else {
ShareOpenGraphContent.Builder contentBuilder = new ShareOpenGraphContent.Builder();
contentBuilder.setPreviewPropertyName("route"); // No namespace here
contentBuilder.setAction(action);
content = contentBuilder.build();
}
So if the user has taken a photo, I want to share it in the story. And to do that, I create a SharePhotoContent. But then it is not linked to the action and the dialog displayed is basically just sharing the photo, which is not the point.
The documentation from facebook states:
To attach pictures of a book to the books.reads action, an app should load images as a Bitmap and pass those to the Share dialog when it's opened.
The Share dialog shows a preview of the story and use Bitmap passed above in the story preview instead of using the object's image.
So what am I missing? Should I first initiate the dialog with the ShareOpenGraphContent and then pass the SharePhotoContent ? if yes how?
Also still regarding the sharing of user generated photos using open graph, do I need to have the Story reviewed?
Thanks
Upvotes: 1
Views: 667
Reputation: 116
It looks like the documentation is incorrect. Here is an example of attaching an image to an OG share dialog invocation.
private void invokeOGShareDialog(Bitmap bitmap) {
// Create OG object
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();
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.setUserGenerated(true)
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.putPhoto("image", photo)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
ShareDialog.show(this, content);
}
Upvotes: 3