我目前正在实施Facebook Fitness共享功能,我希望有一个像nike那样的自定义单元:
我已经托管了我自己的单位对象,并使用以下代码实现了共享按钮:
iv_workout_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Create an object
ShareOpenGraphObject.Builder object = new ShareOpenGraphObject.Builder()
.putString("fb:app_id", "xxxxx")
.putString("og:type", "fitness.course")
.putString("og:title", "example")
.putString("fitness:duration:value", (workout.duration / 1000) + "")
.putString("fitness:duration:units", "s")
.putString("fitness:distance:value", String.format("%.2f", workout.current_distance / 1000f))
.putString("fitness:distance:units", "km")
.putString("fitness:speed:value", (workout.current_distance / (workout.duration / 1000)) + "")
.putString("fitness:speed:units", "m/s")
.putString("fitness:custom_unit_energy:value", 100 + "")
.putString("fitness:custom_unit_energy:units", "http://example.com/fatburn.html");
for (int i = 0; i < workout.location_record.size(); i++) {
object.putDouble("fitness:metrics[" + i + "]:location:latitude", workout.location_record.get(i).getLat());
object.putDouble("fitness:metrics["+i+"]:location:longitude",workout.location_record.get(i).getLong());
if(i == 0) {
object.putString("fitness:metrics["+i+"]:timestamp", workout.timestamp - workout.duration + "");
}else {
if (i == workout.location_record.size() - 1) {
object.putString("fitness:metrics["+i+"]:timestamp", workout.timestamp + "");
}
}
}
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("course", object.build())
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("course")
.setAction(action)
.build();
ShareDialog shareDialog = new ShareDialog((Activity) context);
shareDialog.show(content);
}
});
对于http://example.com/fatburn.html:
<html>
<head>
<meta property="fb:app_id" content="381721038699445" />
<meta property="og:type" content="fitness.unit" />
<meta property="og:url" content="http://exanple.com/fatburn.html" />
<meta property="og:title" content="Fat Burn" />
<meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" />
<!-- Developer defined fitness unit name -->
<meta property="fitness:name" content="Fatburn"/>
</head>
<body>
</body>
</html>
当我点击分享按钮时,弹出Facebook共享对话框,然后按下发布按钮,弹出一个告诉我帖子已分享的吐司。
但是我的墙上没有任何东西......
我的代码中是否遗漏了任何内容?
答案 0 :(得分:0)
在我的研究之后,我必须托管我自己的对象,就像我在更新2中所做的那样。
但它不起作用的原因是我的对象出了问题。
我使用以下工具验证对象并根据它给出的指令修复它,然后我的代码工作!