2011-02-09 7 views
0

Я хочу включить виджет, в котором пользователь добавит URL-адрес страницы фейсбука, и он сможет получить все фиды или последние фиды с определенной страницы и отобразится в поле подобный facebook вентилятор box. Но это должно быть. Как это сделать. Я смог сделать это только для одной конкретной страницы 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() и вставить его как переменную в API Facebook? – benhowdle89

+0

'$ (" # submit "). Click (function (event) {// связать это событие как событие onclick с кнопкой отправки. \t \t \t var searchTerm = $ (" # search "). Val(); // получить введенное пользователем слово для поиска \t \t \t уаг BaseUrl = "http://graph.facebook.com/";? \t \t \t $ .getJSON (BaseUrl + SEARCHTERM + «/ корма предел = 5 & обратного вызова =? ", функция (данные)' –

ответ

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> 

+0

Вам не нужны токены доступа для каждой страницы? –

+0

Это не работает! – B4NZ41

Смежные вопросы