使用 facebook open graph stories v4 将图片附加到动作
Attach picture to action using facebook open graph stories v4
我正在使用 facebook SDK 4. 和 open graph stories api。当没有用户创建的图像时,我可以创建一个动作并共享它,但是在添加图像时,我不知道如何将 SharePhotoContent link 添加到创建的动作中。
我的代码是:
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();
}
所以如果用户拍了照片,我想在故事中分享。为此,我创建了一个 SharePhotoContent。但它并没有 link 执行操作,显示的对话框基本上只是分享照片,这不是重点。
Facebook 的文档指出:
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.
那我错过了什么?我应该先用 ShareOpenGraphContent 启动对话然后传递 SharePhotoContent 吗?如果是怎么办?
还有关于使用 open graph 分享用户生成的照片,我需要让 Story 审核吗?
谢谢
文档好像有误。这是将图像附加到 OG 共享对话框调用的示例。
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);
}
我正在使用 facebook SDK 4. 和 open graph stories api。当没有用户创建的图像时,我可以创建一个动作并共享它,但是在添加图像时,我不知道如何将 SharePhotoContent link 添加到创建的动作中。
我的代码是:
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();
}
所以如果用户拍了照片,我想在故事中分享。为此,我创建了一个 SharePhotoContent。但它并没有 link 执行操作,显示的对话框基本上只是分享照片,这不是重点。
Facebook 的文档指出:
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.
那我错过了什么?我应该先用 ShareOpenGraphContent 启动对话然后传递 SharePhotoContent 吗?如果是怎么办?
还有关于使用 open graph 分享用户生成的照片,我需要让 Story 审核吗?
谢谢
文档好像有误。这是将图像附加到 OG 共享对话框调用的示例。
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);
}