gpt4 book ai didi

javascript - JSON - 从 url 获取 facebook 总数

转载 作者:行者123 更新时间:2023-12-02 17:13:54 27 4
gpt4 key购买 nike

此脚本获取 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 ")获取点赞、分享和评论的总数,但没有成功。

<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 ”吗?

最佳答案

我猜

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

应该做...请务必从 FQL 中的 URL 中删除多余的空格。

看看这个 fiddle :http://jsfiddle.net/e24ey/1/

关于javascript - JSON - 从 url 获取 facebook 总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24601911/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com