Android:OpenGraph Stories在Facebook上与SDK 4.0共享

时间:2015-05-12 11:33:28

标签: android facebook-graph-api facebook-opengraph facebook-android-sdk facebook-share

当玩家解锁徽章时,我正在努力实现与Facebook共享的成就。在facebook开发者控制台中使用对象浏览器创建了一个对象。我制作了动作类型和对象类型并制作了一个自定义故事。现在我被困在试图分享到Facebook的故事。 facebook提供的文件不足。甚至facebook提供的示例代码也使用v3.x

facebook给出的示例代码如下。无法找到任何好的文档。

对象代码

Bundle params = new Bundle();
Request request = new Request(
    Session.getActiveSession(),
    "me/objects/enguru_app:badge",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

行动守则

Bundle params = new Bundle();
params.putString("badge", "http://samples.ogp.me/1114467558579559");
Request request = new Request(
    Session.getActiveSession(),
    "me/enguru_app:unlocked",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

3 个答案:

答案 0 :(得分:6)

At Last想出了我自己的问题。

以下是解决方案:

ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "enguru_app:badge")
            .putString("og:title", "Unlocked Newbie Badge")
            .putString("og:url","xxxx")
            .putString("og:image","xxx")
            .putString("game:points", "10")
            .putString("fb:app_id", "xxx")
            .putString("og:description",
                    "We are rocking. Come and Play with us").build();
    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("enguru_app:unlocked")
            .putObject("badge", object).build();
    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("badge").setAction(action)
            .build();

    ShareDialog.show(Profile.this, content);

我希望这可以帮助那些经历同样问题的人。

答案 1 :(得分:0)

答案 2 :(得分:0)

如果您正在寻找如何在不使用ShareDialog的情况下分享:

ShareApi shareApi = new ShareApi(content);
shareApi.share(new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
});

您也可以查看shareApi.canShare()