当玩家解锁徽章时,我试图实现分享到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
最佳答案
终于解决了我自己的问题。
以下是解决方案:
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);
我希望这能帮助正在经历同样问题的人。