我正在尝试将Facebook分享应用到我的健身应用中,以分享路线,速度,距离等信息。
目前我正在使用Facebook Fitness Run Action来实现这一目标,我得到了以下内容。
现在,我想在此分享帖子中包含更多信息,就像耐克所做的那样:
我很困惑,我不知道在上图中添加像“NikeFuel”这样的“自定义单位”的位置。
我已阅读Facebook文档,但仍不确定应该怎么做。
任何人都能引导我一点点?非常感谢你。
==============更新1 =================
我正在尝试使用以下代码实现它,但它不起作用
ShareOpenGraphObject.Builder objectfatburn = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.unit")
.putString("og:title", "Fat Burn")
.putString("fitness:name", "fatburn");
// Create an object
ShareOpenGraphObject.Builder object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "FitnessApp")
.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", "fatburn");
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("unit", objectfatburn.build())
.putObject("course", object.build())
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("course")
.setAction(action)
.build();
======================更新2 ======================= =
我试图托管以下内容并尝试将其用于分享
<html><head>
<title>OG Sample Object - Sample Course</title>
<meta property="fb:app_id" content="xxxxx">
<meta property="og:type" content="fitness.unit">
<meta property="og:title" content="Fat Burn">
<meta property="og:image" content="https://sstatic.ak.fbcdn.net/images/devsite/attachment_blank.png">
<meta property="fitness:name" content="fatburn">
<link type="text/css" rel="stylesheet" href="/stylesheets/app.css">
</head>
<body>
并且我添加了以下代码来添加我的自定义单元但是......它不起作用......
.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://xxxxxx/fatburn.html");
答案 0 :(得分:1)
看看
我认为在fitness.unit
中使用的fitness:custom_unit_energy
fitness.course
可能会成功。否则,请查看NikeFuel示例的OpenGraph详细信息,以查看他们使用的属性的原因。
据我了解文档,单元对象必须有一个公共网址(“应用程序拥有的对象”),它可用(我不认为它足以动态创建它),意思是您应该在服务器上的某个地方托管它:
<meta property="fb:app_id" content="{your_app_id}" />
<meta property="og:type" content="fitness.unit" />
<meta property="og:url" content="Put your own URL to the object here" />
<meta property="og:title" content="Fat Burn" />
<meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" />