android facebook sdk 4.2打开图形故事和地图

时间:2015-06-06 06:40:20

标签: android facebook sdk opengraph

我正在尝试使用facebook android sdk 4.2版分享健身课程的开放图形故事和位置,

我想有这样的事情:

https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xaf1/t39.2178-6/851557_504281972964839_1538874606_n.png

但地图没有显示

基本上我的代码看起来像这样:

    ShareOpenGraphObject 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)
    .putString("fitness:speed:units", "m/s");

    ArrayList<ShareOpenGraphObject> metrics = new ArrayList<ShareOpenGraphObject>();
    ShareOpenGraphObject.Builder metric1 = new ShareOpenGraphObject.Builder();
    String timestamp1 = dateFormat.format(new Date(realDateTime1));
    metric1.putDouble("fitness:metrics:location:latitude", latitude1);
    metric1.putDouble("fitness:metrics:location:longitude",longitude1);
    metric1.putString("fitness:metrics:timestamp",timestamp1);
    metrics.add(metric1.build());
    ShareOpenGraphObject.Builder metric2 = new ShareOpenGraphObject.Builder();
    String timestamp2 = dateFormat.format(new Date(realDateTime2));
    metric2.putDouble("fitness:metrics:location:latitude", latitude2);
    metric2.putDouble("fitness:metrics:location:longitude",longitude2);
    metric2.putString("fitness:metrics:timestamp",timestamp2);
    metrics.add(metric2.build());

    .....

    object.putObjectArrayList("fitness:metrics", metrics);

    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
     .setActionType("fitness.runs")
     .putObject("fitness:course", object.build())
     .putString("fitness:start_time", startTime)
     .putString("fitness:end_time", endTime)
     .build();

    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
     .setPreviewPropertyName("fitness:course")
     .setAction(action)
     .build();

我做了几次没有成功的尝试,例如,如果我不使用上面显示的度量数组,我将健身:metrics:location:*直接放在原始对象构建器上,地图显示为单个位置。提示?

1 个答案:

答案 0 :(得分:1)

我有一个类似的问题,在我的情况下,我有一个主持健身课程的网络后端,我通过在ShareOpenGrapAction中设置健身课程的网址来解决它。

在网络后端,使用此处所述的参考资料创建健身课程:https://developers.facebook.com/docs/opengraph/guides/fitness

在应用

ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
        .setActionType("fitness.runs")
        .putString("fitness:course", url)
        .build();

ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
        .setPreviewPropertyName("fitness:course")
        .setAction(action)
        .build();

比调用节目

if (shareDialog.canShow(ShareOpenGraphContent.class)) {
    shareDialog.show(content);
}

希望这有帮助!