如何让facebook喜欢数

时间:2015-12-17 11:43:57

标签: facebook facebook-javascript-sdk

我试过这段代码:

 FB.api('/facebook/feed?fields=message,likes',   function(response) {
    document.getElementById("content").innerHTML += response.data[0].likes.count;
 });

但是我得到了#undefined'作为价值。

1 个答案:

答案 0 :(得分:2)

没有likes.count属性。请在下次查看文档...您需要使用

/facebook/feed?fields=message,likes.summary(true).limit(0)

作为查询。您可以在返回的Graph Explorer中尝试此操作

{
  "data": [
    {
      "message": "2015 brought us triumph, tragedy, heartbreak and hope. Here's to all the connections we've made this year, and all the ones we'll make in the next.",
      "id": "20531316728_10154249775416729",
      "likes": {
        "data": [
        ],
        "summary": {
          "total_count": 295795,
          "can_like": true,
          "has_liked": false
        }
      }
    }
  ],
  "paging": {
    "previous": "https://graph.facebook.com/v2.5/20531316728/feed?fields=message,likes.summary%28true%29.limit%280%29&limit=1&format=json&since=1450030400&access_token=&__paging_token=&__previous=1",
    "next": "https://graph.facebook.com/v2.5/20531316728/feed?fields=message,likes.summary%28true%29.limit%280%29&limit=1&format=json&access_token=&until=1450030400&__paging_token="
  }
}

示例:

FB.api('/facebook/feed?fields=message,likes.summary(true).limit(0)',   function(response) {
    document.getElementById("content").innerHTML += response.data[0].likes.summary.total_count;
});