【问题标题】:JSON - get facebook total count from urlJSON - 从 url 获取 facebook 总数
【发布时间】:2014-07-07 01:28:36
【问题描述】:

此脚本获取来自 facebook 粉丝页面的点赞数。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
//Set Url of JSON data from the facebook graph api. make sure callback is set   with a '?' to overcome the cross domain problems with JSON
var url = "https://graph.facebook.com/tenniswarehouse?callback=?";

//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
$.getJSON(url,function(json){
    var html = "<ul><li>" + json.likes + "</li></ul>";
    //A little animation once fetched
    $('.facebookfeed').animate({opacity:0}, 500, function(){
        $('.facebookfeed').html(html);
    });
    $('.facebookfeed').animate({opacity:1}, 500);
});
});
</script>
</head>
<body>
<div class="facebookfeed">
<h2>Loading...</h2>
</div>
</body>
</html> 

Source

我试图让他从一个 url("total_count") 中获取喜欢、分享和 cmets 的总数,但是没有用。

<script type="text/javascript">
$(function() {
//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=    %27http://www.google.com%27?callback=?";

//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
$.getJSON(url,function(json){
var html = "<ul><li>" + json.total_count + "</li></ul>";
//A little animation once fetched
$('.facebookfeed').animate({opacity:0}, 500, function(){
$('.facebookfeed').html(html);
});
$('.facebookfeed').animate({opacity:1}, 500);
});
});
</script>
</head>
<body>
<div class="facebookfeed">
<h2>Loading...</h2>
</div>
</body>
</html>

您能帮我让脚本从链接中获取“total_count”吗?

【问题讨论】:

    标签: javascript json facebook facebook-graph-api facebook-fql


    【解决方案1】:

    我猜

    var html = "<ul><li>" + json.data[0].total_count + "</li></ul>";
    

    应该...确保也从 FQL 中的 URL 中删除多余的空格。

    看看这个小提琴:http://jsfiddle.net/e24ey/1/

    【讨论】:

    • 它不起作用。我无法删除一些空格,因为它在之后不起作用。
    • 我不明白你的意思。您的 FQL 中有多余的空间:WHERE%20url= %27http://www.google.com
    • 这是网址graph.facebook.com/… 把多余的空格去掉了,还是不行。
    • WHAT 完全不起作用?你应该更具体,否则没有人可以帮助你......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多