android - 使用 facebook open graph stories v4 将图片附加到 Action

标签 android facebook facebook-graph-api facebook-opengraph

我正在使用 facebook SDK 4. 和 open graph stories api。当没有用户创建的图像时,我可以创建一个 Action 并共享它,但是在添加图像时,我不知道如何将 SharePhotoContent 链接到创建的 Action 。

我的代码是:

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。但它并没有链接到 Action ,显示的对话框基本上只是分享照片,这不是重点。

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 吗?如果是怎么办?

还有关于使用开放图谱分享用户生成的照片,我需要让 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);

}

关于android - 使用 facebook open graph stories v4 将图片附加到 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31040901/

相关文章:

android - Snackbar 多行文本填充

android - Dropbox 在重新启动应用程序后进行身份验证

android - 如何在两个应用程序之间共享数据

android - cordova-plugin-facebook4 在 Android 上发布图片错误

facebook - 如何通过 graph api 将自定义日期添加到 facebook 时间线

Facebook FQL/Graph - 获取所有当前的戳

android - Unity Android 构建错误 : > Illegal char <? > 在索引 7 : . .\..\l?brary_man?fest\release\AndroidManifest.xml

asp.net - Facebook 页面上的帖子

ios - 如何知道该用户的哪些Facebook friend 已安装我的应用程序?

iphone - Facebook sdk 3.5 请求不起作用