这是我的代码,这个函数正在创建健身指标。
protected ArrayList<ShareOpenGraphObject>
setPathToPostToFacebook(ArrayList<Location> locations){
ArrayList<ShareOpenGraphObject> metrics = new ArrayList<>();
for(Location location : locations){
ShareOpenGraphObject.Builder metric = new ShareOpenGraphObject.Builder();
metric.putDouble("fitness:metrics:location:latitude", location.getLatitude());
metric.putDouble("fitness:metrics:location:longitude",location.getLongitude());
metric.putDouble("fitness:metrics:location:altitude",location.getAltitude());
metric.putString("fitness:metrics:timestamp",new Timestamp(System.currentTimeMillis()).toString());
metric.putInt("fitness:metrics:calories",5);
metric.putDouble("fitness:metrics:distance:value",50);
metric.putString("fitness:metrics:distance:units","km");
metric.putInt("fitness:metrics:steps",100);
metric.putDouble("fitness:metrics:speed:value",50);
metric.putString("fitness:metrics:speed:units","m");
metrics.add(metric.build());//////
}
return metrics;
}
这是其余的内容。
ShareOpenGraphObject.Builder object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "Sample Course")
.putString("og:description", "This is a sample course.")
.putInt("fitness:duration:value", 100)
.putString("fitness:duration:units", "s")
.putInt("fitness:distance:value", 12)
.putString("fitness:distance:units", "km")
.putInt("fitness:speed:value", 5)
.putObjectArrayList("fitness:metrics",metrics);
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("fitness:course", object.build())
.putString("fitness:start_time", FitnessModel.START_TIME)//.putPhoto("image",photo)
.putString("fitness:end_time",new Timestamp(System.currentTimeMillis()).toString())
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
我已经在 facebook 的官方开发者页面上两次问过这个问题,但是他们一次可以回答的问题太多了。如果有人能回答这个问题,我将不胜感激。