如何使用其ID发布自定义Facebook Open Graph故事

时间:2016-04-26 12:51:52

标签: javascript facebook facebook-graph-api

我正在制作基于Javascript的HTML Facebook游戏,我正在创建一个分享按钮,以便玩家在完成关卡时分享他们的分数和排名。

由于不同的玩家将拥有不同的等级和分数,我将玩家的分数发布到他们自己的个人故事中:

function shareResult(){

// Here I'm creating a custom story by inserting the player's rank and score using ``getElementById`` to get the rank and score. This player's unique story is saved in Facebook in ``me/objects/game.achievement`` 

FB.api(

    "/me/objects/game.achievement",
    "POST",

    {        "object": "{\"fb:app_id\":\"607362846726234\",\"og:type\":\"game.achievement\",\"og:url\":\"http://apps.facebook.com/myurlwithmetatags\",\"og:title\":\"I just ranked "+document.getElementById('myrank').innerHTML+" in the game with a score of "+document.getElementById('myscore').innerHTML+"\",\"og:image\":\"https:\\\/\\\/s-static.ak.fbcdn.net\\\/images\\\/devsite\\\/attachment_blank.png\",\"game:points\":\"250\"}"
    },

    function (response) {

      if (response && !response.error) {

        console.log(response);

// Here I'm attemptng to publish the custom story to the player's timeline by telling it to publish the story that has the ID of the newly created story, this ID is returned as ``(response)``, so I store it as the variable ``theachievement``, and then try to publish that:

    var theachievement = response;

    FB.api( 

    "/me/objects/game.achievement",
    "POST",

    {
        "id": theachievement
    },

    function (response) {
      if (response && !response.error) {
         console.log("Story should now be published on player's timeline");
      }
    }
);

此代码已成功创建故事并将其保存在me/objects/game.achievement中(当我在Facebook的图谱API中测试时,排名和分数会正确显示。但是,应该将故事发布到该代码的代码有问题。用户的时间表。

我拥有正确的权限(发布权限),所以我认为代码的后半部分必定存在错误。

对此有任何帮助将非常感谢,提前谢谢!

0 个答案:

没有答案
相关问题