Reputation: 56
I am trying to implement Facebook share to my fitness apps to share information like route, speed, distance, etc.
Currently I am using the Facebook Fitness Run Action to achieve this and I got the following.
Now, I would like to include more information in this share post just like what Nike do:
I am confused and I do not know where to add a "custom unit" like the "NikeFuel" in the above image.
I have read the Facebook document but still not sure what should I do.
Anyone can lead me a little? Thank you so much.
============== Update 1 =================
I am trying to implement it using the following code but it doesn't work
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();
====================== Update 2 ========================
I have tried to host the following and try to use it for sharing
<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>
and i have added the following code to add my custom unit but..... it doesn't work...
.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");
Upvotes: 0
Views: 355
Reputation: 31479
Have a look at
I think fitness.unit
as fitness:custom_unit_energy
used in fitness.course
might do the trick. Otherwise, check the OpenGraph details for the NikeFuel example to probably see why properties they used.
As I understand the docs, the unit object must have a public url ("app-owned object") where it's available ( I don't think it's enough to create it dynamically), meaning that you should host it somewhere on your server:
<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" />
Upvotes: 1