Advertisement
ibnuasad

Show Facebook Group Wall Posts on Website

May 26th, 2013
3,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <?php
  2. /**
  3. Source: http://ranacse05.wordpress.com/2011/02/04/show-facebook-group-wall-on-web-site/
  4.  
  5. Modified on 26 May 2013 by Ibnu Asad (http://www.ibnuasad.org)
  6. + Fixed HTML Styles
  7. + Fixed CSS width values
  8. + Added access token support
  9.  
  10. Instructions:
  11. 1) Get an access token from https://developers.facebook.com/tools/explorer
  12. 1a) Additional Permissions for CLOSED GROUPS, please select "user_groups" & "friends_groups"
  13. 2) Find your Facebook Group ID via http://www.wallflux.com/facebook_id/
  14. **/
  15.  
  16.  
  17. $limit = 5; // The number of posts fetched
  18. $access_token = 'INSERT ACCESS TOKEN HERE';
  19. $group_id = 'INSERT GROUP ID HERE';
  20. $url1 = 'https://graph.facebook.com/'.$group_id.'?access_token='.$access_token;
  21. $des = json_decode(file_get_contents($url1));
  22.  
  23.  
  24. /**echo '<pre>';
  25. print_r($des);
  26. echo '</pre>';**/
  27.  
  28. $url2 = "https://graph.facebook.com/{$group_id}/feed?access_token={$access_token}";
  29. $data = json_decode(file_get_contents($url2));
  30. ?>
  31. <style type="text/css">
  32.  .wrapperfb {
  33.  width:100%;
  34.  border:1px solid #ccc;
  35.  font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
  36.  float:left;
  37.  }
  38.  
  39.  .topfb {
  40.  margin:5px;
  41.  border-bottom:2px solid #e1e1e1;
  42.  float: left;
  43.  width:90%;
  44.  }
  45.  
  46.  .singlefb {
  47.  margin:3px;
  48.  border-bottom:1px dashed #e1e1e1;
  49.  float:left;
  50.  }
  51.  
  52.  .imgfb {
  53.  float:left;
  54.  width:60px;
  55.  text-align:center;
  56.  margin:5px 5px 5px 0px;
  57.  border-right:1px dashed #e1e1e1;
  58.  }
  59.  
  60.  .textfb {
  61.  width:75%;
  62.  float:left;
  63.  font-size:12px;
  64.  }
  65.  
  66.  .afb {
  67.  text-decoration: none;
  68.  color: #3b5998;
  69.  }
  70. </style>
  71.  
  72. <div class="wrapperfb">
  73.   <div class="topfb">
  74.  <a class="afb" href='http://www.facebook.com/home.php?sk=group_<?=$group_id?>&ap=1'>
  75. <?=$des->name?></a>
  76.  <div style="width:100%; margin: 5px">
  77.  <?=$des->description?>
  78.  </div>
  79.  </div>
  80.  <?
  81.  $counter = 0;
  82.  
  83.  foreach($data->data as $d) {
  84.  if($counter==$limit)
  85.  break;
  86.  ?>
  87. <div class="singlefb">
  88.  <div class="imgfb">
  89.  <a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
  90.     <img border="0" alt="<?=$d->from->name?>" src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
  91.  </a>
  92.  </div>
  93.  <div class="textfb">
  94.  <span style="font-weight:bold"><a class="afb" href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
  95. <?=$d->from->name?></a></span><br/>
  96.  <span style="color: #999999;">on <?=date('F j, Y H:i',strtotime($d->created_time))?></span>
  97.  <br/>
  98.  <?=$d->message?>
  99.  </div>
  100.  </div>
  101.  <?
  102.  $counter++;
  103.  }
  104.  ?>
  105. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement