3

I have a facebook site (site, not profil wall) and would like to display the message feed on a webpage. This already works fine if I use

https://graph.facebook.com/177610425663218/feed

But I need an access_token for this. Using the Graph Explorer I can generate a temporary token.

I know I can create an OAuth but I don't want every visitor of my webpage to login into facebook just to see the feeds. There must be another way... Maybe using PHP instead of Javascript?

PiTheNumber
  • 22,828
  • 17
  • 107
  • 180

5 Answers5

4

https://developers.facebook.com/docs/plugins/ provides a list of all plugins that you can embed. However, this does not work if you want to display feed to non-fb-logged-in users.

To solved your problem - have a server side script that accesses this feed and displays it. If this feed is from a FB page, then you will need an access token with "manage_pages" permissions. Using that, you can get the contents using the following (PHP) code:

$response=file_get_contents("https://graph.facebook.com/".$id."/feed&access_token=".$facebook_access_token);
$response_array=json_decode($response,true);
// $id: Page ID

You can also customize this query by adding pagination parameters like since,limit,until etc. Please refer to https://developers.facebook.com/docs/reference/api/ for documentation.

This approach allows you the following advantages:

  • Your Access Token is safe on your server and not visible to public.
  • Your feed can be seen by even a non-logged in user.
  • You can customize the look and feel of your feed since you control the UI.

Disadvantages:

  • Needs you to code and actively maintain a piece of code that does nothing except act like a proxy. Everytime FB changes the structure of it's object, you will need to change this code.
Shreeni
  • 3,222
  • 7
  • 27
  • 39
  • If you have only one or two pages and want to quickly configure things, you can just go to Graph API Explorer (https://developers.facebook.com/tools/explorer) and generate one from there. If you do not wish to use this, then you need an app that will get it from a user using FB.login (https://developers.facebook.com/docs/reference/javascript/FB.login/) or some such FB-Authentication mechanism. – Shreeni Mar 12 '12 at 09:24
  • 1
    Thanks. I already tried the Graph API Explorer but the token I get there is only temporary: "Error validating access token: Session has expired at unix time...". I need a long time token... – PiTheNumber Mar 12 '12 at 09:45
3

You can use https://www.facebook.com/feeds/page.php?id=<your-page-id>&format=json This returns a json object and requires no access token.

You can also use different formats such as xml and rss20.

Hope this helps.

Nick Lucas
  • 317
  • 2
  • 5
2

Although this question has already been answered. I hope this might help someone else.

I've been developing a plugin for an inhouse CMS that needed to pull a facebook feed straight from JUST the users url. This is what I ended up with.

$url = 'url_pulled_from_database';
$url = str_replace('http://www.', 'http://graph.', $url);
$get_id = file_get_contents($url);
$get_id = json_decode($get_id, true);   
$fbID = $get_id['id'];

//THEN CALL THE FUNCTION        
fb_parse_feed($fbID, $maxnumber);

I cant take credit for the fb_parse_feed function, but you can find it here https://gist.github.com/banago/3864515

Once implemented, it worked like a charm on any public page just by using the url.

dvicemuse
  • 370
  • 2
  • 10
  • That would be very helpful for me. Can you show example of how to use that on a public page. Say for this page? https://www.facebook.com/JulianEdelman as example – MicFin Aug 23 '14 at 03:40
1

doing this in windows 8 store app, this seem to work

url = "https://graph.facebook.com/me?fields=feed&access_token=" + fbtoken;

  • This is the same as [Shreeni](http://stackoverflow.com/a/9663836/956397) proposed and it works well if you get an [access token](https://developers.facebook.com/docs/reference/api/page/#page_access_tokens) but [Nick Lucas](http://stackoverflow.com/a/16330887/956397) is nicer because it works without token. Still +1 for your effort and welcome to Stackoverflow :) – PiTheNumber May 07 '13 at 06:55
1

I don't think you can do it without the access token anymore, but check my answer here for detailed steps on getting one and retrieving the feed you want.

Community
  • 1
  • 1
craned
  • 2,991
  • 2
  • 34
  • 38