2011-08-25 5 views
1

いくつかの調査をした後、特定のファンページにある「好き」の数だけプルして印刷しようとしています。しかし、それは何も引っ張っていない。どんな助け?JSONPとJQueryを使用して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 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> 

答えて

5

コンソールでjavascriptエラーが発生します。 body onLoadではなくjquery document ready上で関数を実行してみてください。また、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> 
+0

まだ動作していない - それはコールバック=私は別のドメイン(Facebook)からJSONを引っ張っているので、 –

+0

私の更新をチェックしています。 – bkaid

+0

素晴らしいありがとう!!!! –

0

代わりにIDでURLを呼び出そうとしましたか?また、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> 
関連する問題