Skip to content
February 4, 2011 / ranacse05

Show Facebook Group Wall on web site

I was working last night and my task was to show the facebook groups wall on a normal website . It can be done easily using facebook graph api after working an hour it was done. So lets discuses the steps here.

And the output will be something like this

Facebook Group wall

First get the group name,description and photo.

$group_id = '2204685680';
$url1 = 'https://graph.facebook.com/'.$group_id;
$des = json_decode(file_get_contents($url1));

This will return all the basic info and those will be in Json format, after decoding that we’ll get some data

stdClass Object

(
    [id] => 2204685680
    [version] => 0
    [owner] => stdClass Object
        (
            [name] => Fatih Beyaz
            [id] => 709103042
        )

    [name] => PHP
    [description] => PHP: Hypertext Preprocessor

For anyone who uses PHP.
    [privacy] => OPEN
    [icon] => http://b.static.ak.fbcdn.net/rsrc.php/y_/r/CbwcMZjMUbR.png
    [updated_time] => 2006-07-09T11:39:30+0000
)

Now we have to pull the posts. For this we need to add feed at the end of the previous url , and the code will be like 

$url2 = "https://graph.facebook.com/{$group_id}/feed";
$data = json_decode(file_get_contents($url2));
This will return last 25 wall post , we can get more if we want by using &limit=NUMBER . For the design lets write some css .
<style type="text/css">
 .wrapper {
 width:300px;
 border:1px solid #ccc;
 font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
 float:left;
 }

 .top {
 margin:5px;
 border-bottom:2px solid #e1e1e1;
 float: left;
 width:290px;
 }

 .single {
 margin:5px;
 border-bottom:1px dashed #e1e1e1;
 float:left;
 }

 .img {
 float:left;
 width:60px;
 text-align:center;
 margin:5px 5px 5px 0px;
 border-right:1px dashed #e1e1e1;
 }

 .text {
 width:220px;
 float:left;
 font-size:10px;
 }

 a {
 text-decoration: none;
 color: #3b5998;
 }
</style>
and including all the things together the full code will be like
<?php
header ('Content-type: text/html; charset=utf-8'); 
$limit = 5;

$group_id = '2204685680';
$url1 = 'https://graph.facebook.com/'.$group_id;
$des = json_decode(file_get_contents($url1));


echo '<pre>';
print_r($des);
echo '</pre>';


$url2 = "https://graph.facebook.com/{$group_id}/feed";
$data = json_decode(file_get_contents($url2));
?>
<style type="text/css">
 .wrapper {
 width:300px;
 border:1px solid #ccc;
 font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
 float:left;
 }

 .top {
 margin:5px;
 border-bottom:2px solid #e1e1e1;
 float: left;
 width:290px;
 }

 .single {
 margin:5px;
 border-bottom:1px dashed #e1e1e1;
 float:left;
 }

 .img {
 float:left;
 width:60px;
 text-align:center;
 margin:5px 5px 5px 0px;
 border-right:1px dashed #e1e1e1;
 }

 .text {
 width:220px;
 float:left;
 font-size:10px;
 }

 a {
 text-decoration: none;
 color: #3b5998;
 }
</style>


<div>
 <div>
 <a href='http://www.facebook.com/home.php?sk=group_<?=$group_id?>&ap=1'>
<?=$des->name?></a>
 <div style="width:100%; margin: 5px">
 <?=$des->description?>
 </div>
 </div>
 <?
 $counter = 0;
 
 foreach($data->data as $d) {
 if($counter==$limit)
 break;
 ?>
 <div>
 <div>
 <a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
    <img border="0" alt="<?=$d->from->name?>" src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
 </a>
 </div>
 <div>
 <span style="font-weight:bold"><a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<?=$d->from->name?></a></span><br/>
 <span style="color: #999999;">on <?=date('F j, Y H:i',strtotime($d->created_time))?></span>
 <br/>
 <?=$d->message?>
 </div>
 </div>
 <?
 $counter++;
 }
 ?>
</div>
Enjoy :)
Advertisement

42 Comments

Leave a Comment
  1. joy06 / Feb 5 2011 4:33 am

    Nice Post after a long time :D We want more post from you :P

  2. tania / Mar 23 2011 5:47 am

    This is a nice article..
    Its very easy to understand ..
    And this article is using to learn something about it..

    c#, dot.net, php tutorial

    Thanks a lot..!

  3. Pieter / May 4 2011 3:21 pm

    Hi, it looks very easy indeed. However, I get what you see under here. Did I forget something?
    It’s the first time I write php …

    Thx for any help

    Pieter

    stdClass Object

    (
    [id] => 2204685680
    [version] => 0
    [owner] => stdClass Object
    (
    [name] => Fatih Beyaz
    [id] => 709103042
    )

    [name] => PHP
    [description] => PHP: Hypertext Preprocessor

    For anyone who uses PHP.
    [privacy] => OPEN
    [icon] => http://b.static.ak.fbcdn.net/rsrc.php/y_/r/CbwcMZjMUbR.png
    [updated_time] => 2006-07-09T11:39:30+0000
    )

    name?>
    description?>
    data as $d) { if($counter==$limit) break; ?>
    from->name?>
    from->name?>
    on created_time))?>
    message?>

  4. totokamer / May 10 2011 2:31 pm

    Very nice and useful.
    But if you post a video You don’t see?

  5. Brick / May 11 2011 10:32 pm

    Could this be possible to make into a module for Joomla 1.6?
    Do I need som library on my server? Graph API?
    Where should that be placed on the server?
    and last should it be referred to in the code somewhere?

  6. Brick / May 12 2011 2:27 am

    Nevermind. I figured it out. Thanks a lot for the code! I made a Joomla 1.6 Module out of this and posted it on main content area by {loadposition xx}
    I see now that this is a WordPress-related board, but it worked anyway.
    Very strange that I can’t find an extension that will do this. I have no experience with programming or php, so it took a while to understand how to implement the css. :-)

    Issues:
    1. Events posted on wall didn’t show.
    2. Time format of message is in GMT. -> Don’t know how to change to local time. (+02:00 in summer and +01:00 in winter).
    3. In an event
    properties[0]->text)?>
    the time is given in plain text and in english. Not very usefull for showing when the event will be.

  7. Brick / May 12 2011 4:39 pm

    I got the “$d->created_time” working with time offset, but I’m having problem with “$d->properties[0]->text”

    The event time is +7hours wrong from what was entered on Facebook, and the format is different for different events.

    Event 1: May 18, 2011 at 12:00am
    Event 2: Saturday at 6:00pm

    Should be:
    Event 1: May 17, 2011 at 17:00
    Event 2: Saturday at 11:00

  8. Brick / May 12 2011 4:47 pm

    @Pieter:
    Instead of “/home.php?sk=group_&ap=1

    put

    /group.php?gid=

  9. Brick / May 12 2011 4:50 pm

    This didn’t work.

    Check your group’s address link in facebook, and you will see that you will need to change the first a href link.

  10. Todd Lyda / Jun 7 2011 1:01 am

    Does this not work any more?

    I had used this on a site and it worked beautifully until last week or so.

    Any ideas?

  11. Todd Lyda / Jun 7 2011 2:43 am

    Here is the site where it was working: http://handsandfeetproject.org/michelle-meece/

    We using this for profiles and groups. It just mysteriously stopped working.

  12. Todd Lyda / Jun 7 2011 8:47 pm

    This was a facebook change requiring access tokens. I created an app, generated an access token and added it to the end of $url2 = “https://graph.facebook.com/{$my_fb_uid}/feed and it worked!

    • sheniff / Jun 28 2011 6:50 pm

      Please! I can’t find the way to do what you did in your website. Could you please explain me a little how to use the access_token to retrieve the feeds??

      Thank you very much beforehand!!

      • ranacse05 / Jun 28 2011 9:14 pm

        For access token try this http://developers.facebook.com/docs/authentication/ or you can use the test access token from the graph api examples that is
        2227470867|2.AQCFrSKCmx5TAxcl.3600.1309280400.0-761687689|wSZKUEOObQHik82NHUtzPwSKf4w

      • Todd Lyda / Jun 28 2011 9:20 pm

        <?php
        header ('Content-type: text/html; charset=utf-8');
        $limit = 6;

        $url1 = 'https://graph.facebook.com/&#039;.$my_fb_uid;
        $des = json_decode(file_get_contents($url1));

        echo '

        ';
        print_r($des);
        echo '

        ‘;

        $url2 = “https://graph.facebook.com/{$my_fb_uid}/feed?access_token=222601031087438|fEa02JzC7jP_JuopFqXTtBdz1rM”;
        $data = json_decode(file_get_contents($url2));
        ?>

    • Clogg / Dec 6 2011 6:09 pm

      :( Hi. I know its a bummer, but could you send me like an example of how to do what youve done on that handsfeetproject? something like ” paste this in head, this in body, replace ### parts with what you find there and there and place it along with .php file that looks like this .. on your web”?
      Please.

  13. sheniff / Jun 28 2011 10:12 pm

    ok! thank you a lot!!

    As far as I could see, it seems the access token must be generated by some application of yours and then it will never change, isn’t it?

  14. Todd Lyda / Jun 28 2011 10:20 pm

    Correct. The application doesn’t really do anything, but it does provide me with my AP ID and AP Secret for the access token. Maybe I need to do more with the FB ap to get it to work.

    Your code above + my access token works great until someone posts a picture the group, then the whole feed disappears.

  15. Facebook Group Feed / Aug 30 2011 4:24 am

    See also http://groupfeed.climatesceptics.org/ for the straight rss feed.

  16. assaf / Oct 25 2011 2:54 am

    Hi,
    Great work.
    Somehow it shows only the group header and description without the items…

    • ranacse05 / Oct 25 2011 2:59 am

      You need to pass the access token .

      • assaf / Oct 25 2011 3:01 am

        I did…I register a nwe app, went through all Oaut process, and finally got the key. than I’ve put it here:
        $url2 = “https://graph.facebook.com/{$group_id}/feed?access_token=XXXXXXX”;

        the header shows, but not the items. even the style not affecting like in the example.

  17. assaf / Oct 25 2011 3:27 am

    Is there any option to wrap it in a wordpress widget? there is a huge demand for such thing.

    • ranacse05 / Oct 25 2011 11:01 am

      yes you can bind that with wp , and this post is a bit old so dont know what did they changed on the process .

      • assaf / Oct 25 2011 1:45 pm

        Thanks !

  18. trafalgar / Nov 9 2011 6:35 am

    Thank you for the headstart! For those finding they lose the feed, don’t forget to pass an access token with offline privileges…

  19. fumcbixby / Nov 23 2011 1:16 am

    I’m really new at this and at a loss. How do I create a Facebook App that reveals the Access Token for my Group? I can get to the App Developer page and click on the “create an app”, but that’s about as far as I know how to go. What kind of app do I need to create? (web app, Facebook app, etc). Then what do I do? Sorry for being such a newbie!

  20. fumcbixby / Nov 23 2011 2:29 am

    okay – I think I got a valid Access Token. I just created a basic “App on Facebook” and found the app’s Access Token. It doesn’t relate to the group at all, but maybe that’s okay. But, I have multiple errors showing up (see below). Perhaps this is because I’m using a free php hosting site? Unfortunately our website is built using a template and there’s no way to add php files to it. So, I’m forced to host the file elsewhere. Does anyone know of a free php hosting server that would let me accomplish this task? Thanks!

    Warning: file_get_contents() [function.file-get-contents]: Unable to access https://graph.facebook.com/230628506276 in /www/zzl.org/f/u/m/fumcbixby/htdocs/group3.php on line 7

    Warning: file_get_contents(https://graph.facebook.com/230628506276) [function.file-get-contents]: failed to open stream: No such file or directory in /www/zzl.org/f/u/m/fumcbixby/htdocs/group3.php on line 7

    Warning: file_get_contents() [function.file-get-contents]: Unable to access https://graph.facebook.com/230628506276/feed?access_token=222601031087438|fEa02Jzc7jP_JuopFqXTtBdz1rM in /www/zzl.org/f/u/m/fumcbixby/htdocs/group3.php on line 14

    Warning: file_get_contents(https://graph.facebook.com/230628506276/feed?access_token=222601031087438|fEa02Jzc7jP_JuopFqXTtBdz1rM) [function.file-get-contents]: failed to open stream: No such file or directory in /www/zzl.org/f/u/m/fumcbixby/htdocs/group3.php on line 14
    .

    Warning: Invalid argument supplied for foreach() in /www/zzl.org/f/u/m/fumcbixby/htdocs/group3.php on line 68

    • ranacse05 / Feb 21 2012 11:22 am

      Sorry for late reply but this is what i got

      {
      “error”: {
      “message”: “Invalid OAuth access token signature.”,
      “type”: “OAuthException”,
      “code”: 190
      }
      }

  21. fumcbixby / Nov 24 2011 10:19 pm

    Okay – got it figured out. Found a free hosting site that worked. However, it is not ideal using that option. SO… I posted the question to a Javascript forum and got a response of how to do this using only Javascript and HTML. This will let anyone integrate their Facebook Group with their Facebook FanPage as well!

    http://www.codingforums.com/showthread.php?p=1162842#post1162842

  22. shital / Nov 25 2011 6:59 pm

    Hi this is a nice code

    but i want something new.
    means if i add some news on my websites, and i want to display this news on my facebook wall.
    so what i do for this.
    please help me for this.
    please give me code on php format.

    kindly reply
    shital

    • ranacse05 / Nov 25 2011 9:22 pm

      Google for the rss feed poster .

  23. Abraar / Jan 12 2012 12:08 pm

    You have bring all the feeds on your website its good. But how i can comment from website? Can you help?

    • ranacse05 / Jan 12 2012 12:16 pm

      you need to use custom coded app for that , last time i checked adding comment using api has a bug so not sure if it works now or not .

  24. Gadget Freak / Jan 15 2012 1:42 am

    Thanks will be working with your code really appreciate the effort :)

  25. ugo / Feb 7 2012 5:35 am

    That code works for secret group?

    • ranacse05 / Feb 21 2012 11:20 am

      if and only if you are the member and you can input your app access token at the end of the URL .

  26. Damo / Feb 13 2012 6:28 pm

    Hi, Got this working with groups so thanks very much for that, but how do I get it working with profiles?

    When I exchange the group id for the profile id I get a link to the profile but no feed?

    Any Ideas?

  27. cyclopsthere / Feb 21 2012 10:05 am

    I’ve been racking my brain on how to use this on a wordpress site and no luck.

    Any chance this could be a plugin?:)

    • ranacse05 / Feb 21 2012 11:16 am

      Its a bit tough to be a plugin bcoz now you need the access token to get that data . So if you plan to develop the plugin you have to guide the users to collect the access token and then in put that token , except that it’ll not work .

  28. cyclopsthere / Feb 21 2012 7:59 pm

    So it won’t work even if I get an access token?

    I’m just trying to use it on one site but haven’t been able to get it to work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.