android - Android Facebook SDK 4.0 中的 Facebook OpenGraph 故事

标签 android facebook facebook-opengraph facebook-sdk-4.0

关注此tutorial ,我正在尝试使用 Facebook SDK 4.0 在 Android 应用程序中实现 OpenGraph 故事。
我已经阅读了很多 Facebook 文档,并了解(理论上)OpenGraph 故事应该如何运作。但主要问题是我无法在 SDK 4.0 中实现它,因为教程和文档中的所有代码示例都引用了旧 SDK 的方法。我所有让它工作的尝试(更改操作、对象)都失败了。

这是我的代码(根据 documentation ):

// Create an 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();

// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
        .setActionType("books.reads")
        .putObject("books:book", object)
        .build();

// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
        .setPreviewPropertyName("books:book")
        .setAction(action)
        .build();

ShareButton shareButton = (ShareButton)findViewById(R.id.shareButton);
shareButton.setShareContent(content);
shareButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {

    @Override
    public void onSuccess(Result result) {
        Log.i(TAG, "SHARING SUCCESS!");
    }

    @Override
    public void onError(FacebookException error) {
        Log.e(TAG, "SHARING ERROR! - " + error.getMessage());
    }

    @Override
    public void onCancel() {
        Log.w(TAG, "SHARING CANCEL!");
    }
});

我得到了什么(通过我所有的尝试): enter image description here

Action Requires At Least One Reference: The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: book.

请解释一下,如何在 FB SDK 4.0 中正确使用 OpenGraph,以及使用 SDK 4.0 方法正确使用 ObjectsActions

最佳答案

对话框的 webview 版本存在错误,该错误已得到修复。您需要对代码做一点小改动,我也会更新我们的文档:

// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
    .setActionType("books.reads")
    .putObject("book", object)  // <--- don't namespace the object on the action
    .build();

// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
    .setPreviewPropertyName("book")  // <--- don't namespace the preview property
    .setAction(action)
    .build();

关于android - Android Facebook SDK 4.0 中的 Facebook OpenGraph 故事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29474049/

相关文章:

prerender - OG 标签不适用于 React-helmet 和 Netlify

facebook - 翻译不适用于开放图谱时间轴 View 中的预览故事

android - 如何从 UI 线程运行特定类型的任务?

android - 使用 jsoup 解析获取 href 那些有 title 的人

ios - Facebook SDK 3.1 - com.facebook.sdk 使用 [facebook 授权 :permissions] 进行身份验证时出现错误 5

xcode - Cocos2d 委托(delegate)回调不起作用

java - 如何在 Looper.getMainLooper 中运行的代码上使用 Mockito 的验证?

android - 为什么 Rxjava 会导致内存泄漏

PHP curl 用于下载 Facebook 视频

jquery - 更新 html 标题和元数据 :title with jquery