Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show facebook feed messages from my site without access_token?

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?

like image 560
PiTheNumber Avatar asked Oct 20 '25 02:10

PiTheNumber


2 Answers

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.
like image 126
Shreeni Avatar answered Oct 21 '25 16:10

Shreeni


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.

like image 45
Nick Lucas Avatar answered Oct 21 '25 15:10

Nick Lucas