如何获得Facebook帖子喜欢?

时间:2017-06-27 09:59:46

标签: facebook-graph-api facebook-javascript-sdk

我正在尝试使用Graph API检索FB Post Likes and Reactions。我用于检索帖子的' LIKE',' LOVE'' HAHA' 的代码将在下面分享。

<script type="text/javascript">
var postID = '';
var access_token = '';
var refreshTime = 1;
var defaultCount = 0;
var reactions = ['LIKE', 'LOVE', 'HAHA'].map(function (e) {
    var code = 'reactions_' + e.toLowerCase();
    return 'reactions.type(' + e + ').limit(0).summary(total_count).as(' + code + ')'
}).join(',');

function refreshCounts() {
    var url = 'https://graph.facebook.com/v2.8/?ids=' + postID + '&fields=' + reactions + '&access_token=' + access_token;
    $.getJSON(url, function(res){
        var v1 = res[postID].reactions_like.summary.total_count;
        var v2 = res[postID].reactions_love.summary.total_count;
        var v3 = res[postID].reactions_haha.summary.total_count;
        $('#counter1').text(v1);
        $('#counter2').text(v2);
        $('#counter3').text(v3);
    });
}

$(document).ready(function(){
    setInterval(refreshCounts, refreshTime * 3000);
    refreshCounts();
});
</script>

但是代码显示了两个{}而不是结果。

1 个答案:

答案 0 :(得分:0)

为什么不使用javascript SDK?

constructor(){
 super();
 this.state = {isLoggedIn : false, email :"", password : ""};
}

这对我有用