【问题标题】:Facebook custom unit for Fitness is not showing健身的 Facebook 自定义单元未显示
【发布时间】:2015-09-21 04:54:54
【问题描述】:

我目前正在实现 Facebook 健身分享功能,我想拥有一个自定义单元,就像耐克所做的那样:

我已经托管了我自己的单元对象并使用以下代码实现了分享按钮:

 iv_workout_share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                    // Create an object
                    ShareOpenGraphObject.Builder object = new ShareOpenGraphObject.Builder()
                    .putString("fb:app_id", "xxxxx")
                    .putString("og:type", "fitness.course")
                    .putString("og:title", "example")

                    .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", "http://example.com/fatburn.html");


            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("course", object.build())
                    .build();

            // Create the content
            ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                    .setPreviewPropertyName("course")
                    .setAction(action)
                    .build();


            ShareDialog shareDialog = new ShareDialog((Activity) context);
            shareDialog.show(content);
        }
    });

对于http://example.com/fatburn.html

<html>
<head>
<meta property="fb:app_id" content="381721038699445" /> 
<meta property="og:type"   content="fitness.unit" /> 
<meta property="og:url"    content="http://exanple.com/fatburn.html" /> 
<meta property="og:title"  content="Fat Burn" /> 
<meta property="og:image"  content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" /> 
<!-- Developer defined fitness unit name -->
<meta property="fitness:name" content="Fatburn"/>
</head>
<body>
</body>
</html>

当我点击分享按钮时,会弹出 Facebook 分享对话框,然后我按下发帖按钮,会弹出一个 toast 告诉我帖子已分享。

但我的墙上什么都没有显示...

我是否遗漏了代码中的任何内容?

【问题讨论】:

  • 您能否检查是否发布了 anything,即您的 Facebook 活动日志中也没有出现任何内容?另外,请在您的问题中添加您使用的是哪个 SDK 版本。
  • 谢谢@derabbink,我的问题已经解决了。

标签: android facebook share facebook-opengraph


【解决方案1】:

经过研究,我必须托管自己的对象,就像我在更新 2 中所做的那样。

但它不起作用的原因是我的对象有问题。

我使用以下工具来验证对象并根据它给出的指令修复它,然后我的代码就可以工作了!

https://developers.facebook.com/tools/debug/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多