gpt4 book ai didi

android - 使用 Open Graph API 在 Android 中发布健身类(class)数据点位置

转载 作者:行者123 更新时间:2023-11-29 14:50:36 24 4
gpt4 key购买 nike

我正在开发一个 Android 健身应用程序,我正在尝试使用 Open Graph API 在 Facebook 上发布 Activity 数据点位置。我使用了以下代码,它只发布了 location1,但没有添加到列表中的其他位置。

public void shareWorkout (View v){
if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
OpenGraphObject course = OpenGraphObject.Factory.createForPost(null);
course.setType("fitness.course");
course.setTitle("Walking Course");
course.setUrl("http://samples.ogp.me/136756249803614");
course.setDescription("walked a course");

GraphObject location1 = GraphObject.Factory.create();
location1.setProperty("latitude", 31.90592568833381f);
location1.setProperty("longitude", 35.20052916370332f);
location1.setProperty("altitude", 0.0f);

GraphObject location2 = GraphObject.Factory.create();
location2.setProperty("latitude", 31.912331976927817f);
location2.setProperty("longitude", 35.205821581184864f);
location2.setProperty("altitude", 0.0f);

List<GraphObject> locations = new ArrayList<GraphObject>();
locations.add(location1);
locations.add(location2);

GraphObject metrics = GraphObject.Factory.create();
metrics.setProperty("location", locations);

course.getData().setProperty("metrics", metrics);

OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("course", course);

FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this,
action, "fitness.walks", "course").build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
}

最佳答案

我还尝试在 Facebook 上分享一门类(class)。

喜欢facebook Submission Criteria提到你应该包括尽可能多的可用的适当指标(速度、地理点、距离)。

因此,对于每个新位置,您必须创建一个新的度量对象,其中包含位置、时间戳、距离和配速,并将此度量数组添加到度量属性。

这是我的工作示例:

private void shareWorkout(Location[] locations) {
NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
doubleFormat.setMaximumFractionDigits(6);
doubleFormat.setMaximumIntegerDigits(3);
doubleFormat.setGroupingUsed(false);

OpenGraphObject course = OpenGraphObject.Factory
.createForPost("fitness.course");
course.setTitle("Sample Course");
List<GraphObject> metrics = new ArrayList<GraphObject>();
Location prevLocation = null;

for (Location location : locations) {
GraphObject metric = GraphObject.Factory.create();
double distance = calcDistance(prevLocation, location);
double speed = location.getSpeed() * LocationUtils.MS_TO_KMH;
double pace = speed == 0 ? 0.0 : 60.0 / speed;
metric.setProperty("location:longitude",
doubleFormat.format(location.getLongitude()));
metric.setProperty("location:latitude",
doubleFormat.format(location.getLatitude()));
metric.setProperty("location:altitude",
doubleFormat.format(location.getAltitude()));
metric.setProperty("timestamp",
StringUtils.formatDateTimeIso8601(location.getTime()));
metric.setProperty("distance:value", doubleFormat.format(distance));
metric.setProperty("distance:units", "km");
metric.setProperty("pace:value", doubleFormat.format(pace));
metric.setProperty("pace:units", "s/m");
metrics.add(metric);
prevLocation = location;
}
GraphObject courseData = course.getData();
courseData.setProperty("metrics", metrics);
courseData.setProperty("distance:value", calcTime(locations));
courseData.setProperty("distance:units", "min");
courseData.setProperty("distance:value",
doubleFormat.format(calcTotalDistance(locations)));
courseData.setProperty("distance:units", "km");
OpenGraphAction action = GraphObject.Factory
.create(OpenGraphAction.class);
action.setProperty("course", course);
action.setType("fitness.walks");

RequestBatch requestBatch = new RequestBatch();
Request request = Request.newPostOpenGraphActionRequest(
Session.getActiveSession(), action, shareCallback);
requestBatch.add(request);
requestBatch.executeAsync();
}

关于android - 使用 Open Graph API 在 Android 中发布健身类(class)数据点位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19427238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com