Apidcloud

Working javascript example - retrieving facebook page feed

Nov 23rd, 2014
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     function getUserData() {
  3.     FB.api('/Gibbo2D/posts', { limit: 10 }, function(response) {
  4.         console.log(response.data);
  5.        console.log(response.data.length)
  6.        for (var i=0, l=response.data.length; i<l; i++) {
  7.           var post = response.data[i];
  8.           console.log(post)
  9.           if (post.message) {
  10.              console.log('Message: ' + post.message);
  11.           } else if (post.attachment && post.attachment.name) {
  12.              console.log('Attachment: ' + post.attachment.name);
  13.           }
  14.        }
  15.     });
  16. }
  17.  
  18. window.fbAsyncInit = function() {
  19.     //SDK loaded, initialize it
  20.     FB.init({
  21.         appId      : 'APP-ID',
  22.         xfbml      : true,
  23.         version    : 'v2.2'
  24.     });
  25.  
  26.     //check user session and refresh it
  27.     FB.getLoginStatus(function(response) {
  28.         if (response.status === 'connected') {
  29.             getUserData();
  30.         } else {
  31.             //user is not authorized
  32.         }
  33.     });
  34. };
  35.  
  36. //load the JavaScript SDK
  37. (function(d, s, id){
  38.     var js, fjs = d.getElementsByTagName(s)[0];
  39.     if (d.getElementById(id)) {return;}
  40.     js = d.createElement(s); js.id = id;
  41.     js.src = "//connect.facebook.net/en_US/sdk.js";
  42.     fjs.parentNode.insertBefore(js, fjs);
  43. }(document, 'script', 'facebook-jssdk'));
  44.    
  45. </script>
RAW Paste Data