2011-02-09 190 views
0

我想要包含一個小部件,用戶將在其中添加Facebook粉絲頁面的網址,並且他應該能夠從特定頁面獲取所有提要或最近的提要,並將它顯示在一個框中像Facebook粉絲箱。但它應該。我該怎麼做,我只能爲一個特定的臉書頁面做到這一點。它應該動態添加。所以每個用戶可以輸入不同的Facebook粉絲頁面鏈接,他應該能夠得到它。Facebook粉絲頁面提要

非常感謝

<!DOCTYPE HTML> 

Facebook的飼料

<script src="jquery.ui.core.js"></script> 
<script src="jquery.ui.widget.js"></script> 

<script type="text/javascript"> 
$(document).ready(function(){ 
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 Baseurl = "http://graph.facebook.com/"; 
    var search= $("fburl").val(); 

    //Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data. 
    $.getJSON(Baseurl + search + "feed?limit=5&callback=?",function(json){ 
     var html = "<ul>"; 
      //loop through and within data array's retrieve the message variable. 
      $.each(json.data,function(i,fb){ 
       html += "<li>" + fb.message + "</li>"; 
      }); 
     html += "</ul>"; 


     //A little animation once fetched 
     $('.facebookfeed').animate({opacity:0}, 500, function(){ 

       $('.facebookfeed').html(html); 

                   }); 

     $('.facebookfeed').animate({opacity:1}, 500); 

    }); 

}); 

}); 
</script> 

</head> 

<body> 
<input type="text" value="facebookurl" name="facebook_feeds" id="fburl"/> 
<input type="submit" id="submit" /> 

    <div class="facebookfeed"> 

    </div> 

</body> 
</html> 
+1

你不能只是添加一個文本字段並獲取它的.val()並將其作爲變量插入到Facebook API中? – benhowdle89 2011-02-09 11:48:31

+0

`$(「#submit」)。click(function(event){//將它作爲一個onclick事件連接到提交按鈕 \t \t \t var searchTerm = $(「#search」)。val(); //獲取用戶輸入的搜索詞 \t \t \t VAR的baseUrl = 「http://graph.facebook.com/」; \t \t \t $ .getJSON(+的baseUrl +搜索關鍵詞「/供給限制= 5&回調=? 「,函數(數據)` – 2011-02-09 11:55:30

回答

2

我得到了解決這個問題,我包括下文

<html> 
<head> 
    <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 facebookname= document.getElementById("fname").value; 

alert("You are searching for: " + facebookname); 

var url = "http://graph.facebook.com/" + facebookname + "/feed?limit=5&callback=?"; 

    //var url = "http://graph.facebook.com/jeevan.dongre/feed?limit=5&callback=?"; 



    //alert(url); 
    //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>"; 
      //loop through and within data array's retrieve the message variable. 
      $.each(json.data,function(i,fb){ 
       html += "<li>" + fb.message + "</li>"; 
      }); 
     html += "</ul>"; 


    // $('.facebookfeed').html(html).slideDown(200); 
     //A little animation once fetched 
     $('.facebookfeed').animate({opacity:0}, 500, function(){ 

       $('.facebookfeed').html(html); 

                   }); 

     $('.facebookfeed').animate({opacity:1}, 500); 

    }); 



}; 

//onload="fbFetch()" 
</script> 



</head> 
    <body > 
    <center><h1>Friend's Page Feed</h1></center> 
     <table border=1 width="600px" align="center"> 
      <tr> 
       <td width="200px";> 
        Enter Facebook name here: 
       </td> 
       <td width="400px;"> 
        <input type=text name="fname" id="fname" > 
       </td> 
      </tr> 
      <tr> 
       <td colspan="2"> 
        <input type=submit value=enter onclick="fbFetch()"> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="2"> 

         <div class="facebookfeed"> 
          <h2>Content will load here...</h2> 
         </div> 
       </td> 
      </tr> 
     </table> 
    </body> 
源代碼