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
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












Nice Post after a long time
We want more post from you
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..!
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?>
Very nice and useful.
But if you post a video You don’t see?
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?
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.
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
@Pieter:
Instead of “/home.php?sk=group_&ap=1
put
/group.php?gid=
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.
Does this not work any more?
I had used this on a site and it worked beautifully until last week or so.
Any ideas?
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.
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!
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!!
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
<?php
header ('Content-type: text/html; charset=utf-8');
$limit = 6;
$url1 = 'https://graph.facebook.com/'.$my_fb_uid;
$des = json_decode(file_get_contents($url1));
echo '
‘;
$url2 = “https://graph.facebook.com/{$my_fb_uid}/feed?access_token=222601031087438|fEa02JzC7jP_JuopFqXTtBdz1rM”;
$data = json_decode(file_get_contents($url2));
?>
Please.
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?
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.
See also http://groupfeed.climatesceptics.org/ for the straight rss feed.
Hi,
Great work.
Somehow it shows only the group header and description without the items…
You need to pass the access token .
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.
Is there any option to wrap it in a wordpress widget? there is a huge demand for such thing.
yes you can bind that with wp , and this post is a bit old so dont know what did they changed on the process .
Thanks !
Thank you for the headstart! For those finding they lose the feed, don’t forget to pass an access token with offline privileges…
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!
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
Sorry for late reply but this is what i got
{
“error”: {
“message”: “Invalid OAuth access token signature.”,
“type”: “OAuthException”,
“code”: 190
}
}
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
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
Google for the rss feed poster .
You have bring all the feeds on your website its good. But how i can comment from website? Can you help?
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 .
Thanks will be working with your code really appreciate the effort
That code works for secret group?
if and only if you are the member and you can input your app access token at the end of the URL .
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?
for profile the link will be http://graph.facebook.com/USERID/feed/?access_token=ACCESS_TOKEN
and no need to say you need the access token of the user for that app , FYI for each application each users have a unique token.
Hope that will solve your problem .
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?:)
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 .
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.