如何通过Facebook Open Graph发布游戏

时间:2018-07-15 12:41:50

标签: android facebook facebook-opengraph

我正在开发一些测验应用程序,并希望在Facebook上发布玩家的成就。

由于我要发布成就图片,而Facebook的链接共享不再支持添加图片,因此我决定使用Open Graph。

我成功地以“ fitness.course”的对象类型发布了示例源,但是对于“ game.achievement”的对象类型仍然有麻烦。

出现“共享对话框”,并且在单击“发布”按钮之前似乎还可以。但是,单击发布按钮后,我无法在我的Facebook墙上找到该帖子。

这是我的源代码。

    // Set image with the image on the file path
    Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .setUserGenerated(true)
            .build();

    // set object
    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "game.achievement")
            .putString("og:title", "App Name")
            .putString("og:description", "You achieved Golden madal")
            .putInt("game:point", 100)
            .build();

    // set action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("games.achieves")
            .putObject("game.achievement", object)
            .putPhoto("image", photo)
            .build();

    // set content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("game.achievement")
            .setAction(action)
            .build();

    mShareDialog.show(content);

供您参考,以下是我成功使用的示例源代码

    // Set image with the image on the file path
    Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .setUserGenerated(true)
            .build();

    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
           .putString("og:type", "fitness.course")
           .putString("og:title", "App Name")
           .putString("og:description", "You achieved Golden madal")
           .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")
           .build();

   ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
           .setActionType("fitness.runs")
           .putObject("fitness:course", object)
           .putPhoto("image", photo)
           .build();

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

非常感谢您的努力。

1 个答案:

答案 0 :(得分:0)

我想我有这个理由。真令人失望。 game.achievement的Open Graph似乎已被贬值。请参阅链接https://developers.facebook.com/docs/games/services/scores-achievements?locale=en_US

  

Scores API和Achievements API计划弃用。作为   2018年4月4日,它们将仅返回空数据集,并且将   在不久的将来不推荐使用。请查看更改日志以了解更多   信息。

facebook也贬值了Custom Open Graph。请参阅链接https://developers.facebook.com/docs/sharing/opengraph/custom-open-graph-deprecation