尝试使用JSONP和JQuery从facebook粉丝页面中获取喜欢的人数
所以我试着拉出来,打印出某个粉丝页面喜欢的数量,在做了一些研究之后——我发现这应该是可行的,但它不会拉任何东西。有什么帮助吗尝试使用JSONP和JQuery从facebook粉丝页面中获取喜欢的人数,jquery,json,facebook,facebook-graph-api,Jquery,Json,Facebook,Facebook Graph Api,所以我试着拉出来,打印出某个粉丝页面喜欢的数量,在做了一些研究之后——我发现这应该是可行的,但它不会拉任何东西。有什么帮助吗 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> function fbFetch(){
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function fbFetch(){
//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>" + 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 onload="fbFetch()">
<div class="facebookfeed">
<h2>Loading...</h2>
</div>
</body>
</html>
控制台中出现javascript错误。尝试在jquery文档就绪而不是body onLoad上运行该函数。另外,没有定义likes,它应该是json.likes
<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>
控制台中出现javascript错误。尝试在jquery文档就绪而不是body onLoad上运行该函数。另外,没有定义likes,它应该是json.likes
<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>
您是否尝试过通过url的ID来调用它?同样的https/http协议也适用于这里。您可能需要使用document.location.protocol调用url,以匹配调用文档的当前协议
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function fbFetch(){
//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 = document.location.protocol + "//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>" + 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 onload="fbFetch()">
<div class="facebookfeed">
<h2>Loading...</h2>
</div>
</body>
</html>
您是否尝试过通过url的ID来调用它?同样的https/http协议也适用于这里。您可能需要使用document.location.protocol调用url,以匹配调用文档的当前协议
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function fbFetch(){
//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 = document.location.protocol + "//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>" + 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 onload="fbFetch()">
<div class="facebookfeed">
<h2>Loading...</h2>
</div>
</body>
</html>
仍然不起作用-那个?回调=?这是因为我正在从另一个域FaceBook中提取JSON,我会这么做!还有,你能帮我做点别的吗?我将ul>li更改为带有id的div,这很好,但在这个文件的末尾我添加了这个,但它不起作用:-/var x=document.getElementsByClassNameconnect\u widget\u button\u count\u count[0]。innerHTML;如果x<153{document.writemarked}或者{document.writeddn不起作用}@Marco:你应该这样做,因为它似乎与这个没有关系。仍然不起作用-那个?回调=?这是因为我正在从另一个域FaceBook中提取JSON,我会这么做!还有,你能帮我做点别的吗?我将ul>li更改为带有id的div,这很好,但在这个文件的末尾我添加了这个,但它不起作用:-/var x=document.getElementsByClassNameconnect\u widget\u button\u count\u count[0]。innerHTML;如果x<153{document.writeworked}或者{document.writeddn不起作用}@Marco:你应该这样做,因为它似乎与这个没有关系。