views:

172

answers:

4

Hi! I want to connect to public facebook page or group and list all entries from the wall on a personal website. I will use PHP on my server so that would be the best solution for me. Or javascript.

Could anyone explain or perhaps give a working code on how to do this? Or just all steps nessesary for making this?

If its possible to handle information about person, date, description ... for each post, that would be great! So my layout could be customized.

Thanks for helping me out here!

A: 

What you are talking about, as far as I can tell, is Web Scraping. What you would do is get the URL of the group, use the file_get_contents($url) command in PHP to get the file, and then analyze it in PHP.

I'd suggest brushing up on your regular expressions for this, as it'll be important to review the HTML that Facebook uses for the wall posts. You'll be able to get the information that you're looking for from the HTML.

I would post some example code, but that's on another computer, far far away. Still, should be a good start.

Edit: Adding in some example code:

 $URL = "http://facebook.com/group=5343242" (or whatever the URL structure is for the facebook group)
$groupPage = file_get_contents($URL)

Here's the link to the PHP pages on Regular Expressions:

http://www.php.net/manual/en/book.pcre.php

Althane
Interesting. Would love to see an example of this kind of solution, and I will check out the link you posted.
I think your best bet is to check out the API as the others suggested. My suggestion probably will involve a lot more work for you than the others.
Althane
Ok tnx. Still an inteserting thought you have there :)
A: 

Check out the facebook api. It comes with working examples for eg php. developers.facebook.com

Nicolas78
Hi! I tried that, but I guess I did not understand what solution to use and how to use it. Be happy to get more info. Tnx!
well programming against the facebook api is a bit of a topic in itself. serg's answer is basically an extended version of mine, be sure to check his links. You can also start here http://github.com/facebook/php-sdk/ which is the PHP interface to the Facebook API. I guess writing a complete solution is a bit out of scope and would only help you until you run into the first problem. It's a very powerful and timely system, so I'd encourage you to dive a bit into the water, see how far you get with the tutorials and come back once you have more concrete questions
Nicolas78
if there just was an easy example on the web on how to get the wall of a specific page/group. But I guess I have to get my glasses on and read some more :) Tnx for the startup help :)
A: 

You need to run FQL on stream table and provide id of a page or group you are interested in as source_id (fb docs have some explanation and examples). Once you get stream data you can dig deeper and get user who left this post or any other data you need again through FQL.

There are many ways of running FQL - it could be done in JS API, PHP API, or through old REST API.

serg
This sounds like the best solution. Do you have time to give me a working example on how to connect to a page or group and return a xml structure of the wall? I use PHP.Do you need to include some kind of facebook file with working methods?Thanks for the help
@user412264 If you are not familiar with facebook api at all you just need to read documentation yourself first. I wouldn't be able to explain it all to you here. I suggest starting with JavaScript api (http://developers.facebook.com/docs/reference/javascript/) as it is better documented (and easier imo). Once you made some progress then converting your js api code into php api should be pretty straight forward.
serg
Ok. I will try to look at the js api. Do you need to register an application at facebook to be able do this kind of tasks?
@user412264 it's hard to say. Some methods don't require providing app id, but the majority do. If registering an app is not a limitation for you I would register one, it would open more doors.
serg
Ok. I'm just a bit confused on why to make an app for a code you will have on another server. In my case I just need a way to pull out posts on a wall for a group/page and show it on a php website. Not easy to find a example for this. But thanks for helping me out! Things are getting clearer, but still a bit confusing :)
@user412264 creating an application doesn't necessary mean that it should be hosted on facebook. You will receive public/secret api keys that you would use to make API calls from your site.
serg
+1  A: 

use the facebook graph api urls that they provide

python code using simplejson parser

keyword="old spice"
searchurl='http://graph.facebook.com/search?q='+keyword
resp=urllib2.urlopen(searchurl)
pageData=resp.read()
json = simplejson.loads(pageData)
posts=json['data']
for p in posts:
    postid=p['id']
    username=p['from']['name']
    posterimg=p['icon']
    comment=p['message']
JiminyCricket
dunno how far you get with that, but +1 for a neat solution to what I'd have thought of as a larger problem
Nicolas78
cool! Need to look closer to this code since I'm not familiar with python. Tnx for the example!