April 2, 2014 12:10 pm

How to get your Facebook Feed with graph API using PHP

Today I am going to show you how to pull your Facebook profile feed or any of your friends public feeds, I have filtered it to get only status, photo, video and link sharing with data type filters. To perform this action you need Facebook extended permission of read_stream. This tutorial can help user who want to make application to use Facebook users shared status videos, images and links and call some action ( send SMS or send email ) on each update.

How to get your Facebook Feed with graph API using PHP

First of all we need to create Facebook login authentication which we already explain in this post How to Login with Facebook Graph API in PHP now this code explain you how to get feeds in graph api.


Application configuration file, modify CALL BACK URLYour App ID and Your App Secret values.


Contains PHP code. Get Facebook code and on that code base get access token of current user.

This code will get access token and make request to graph api to get news feed.

Returned data will be in json so we have converted json to array and create a grid to view data on website.

In above code we have filtered data and show in grid view with its titles, message and images.

First of all we get all data with type photo, status, video, link and then filtered it by its status type and show them on the website. You can add your status’s comments and likes on the same time. It return you complete activity like your comments, likes, friend added, shared status any where on the Facebook every thing you are doing.

You can also get your friends public updates by doing simple changes like below.

Simply change me to some id it will get all public statuses of that person.

We are extracting only latest 25 statuses of yours but you can navigate them by given pagination links for next and previous.

Free download code and a live demo available.

I hope this tutorial helps you so please don’t forget to give us your feedback.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • siddhu

    Nice post,nice demo

  • Sergio L.

    Hello, and Thank you for the amazing tutorial!
    Just want to ask….is this version working properly for all? I only have a blank page. 🙁 Thanks

    • huzoorbux

      try to debug it and send me exact error

  • jloa

    Let me help u with obtaining token w/o user interaction. Only server-side request needed.
    Just make a curl request to https://graph.facebook.com/oauth/access_token?client_id=…&client_secret=…&grant_type=client_credentials
    The result will be a string as follows access_token=blahblahblah.
    Wrap that curl request in a function/method and remove the param name, to get the actual token string
    str_replace(‘access_token=’, ”, $curlResponce);

    That’s it. U are welcome ^_^

  • sareer

    Sir I m the biggner I want to show a friend profile is it

  • Debakant M.

    What the fuck?? First of all its asking me to subscribe to feedburner even after subscribing I still am not able to download the script!!

  • Debakant Mohanty.

    I tried changing the me here: // change “me” to your friend Facebook id
    $graph_url = “https://graph.facebook.com/me/feed?access_token=”.$params[‘access_token’]; to other id, but not working!

  • test

    Fatal error: Call to undefined function file_get_contents_curl() in
    on line 29

  • sam

    not sure if this tut is what im after – I want to have a website (phone apps to follow) that allows me to have the user log in via FB, then display their news feed on the site…however the news feed will be filtered to show posts that have been liked/shared the most by their friends….possible??

  • looking

    Fatal error: Call to undefined function file_get_contents_curl() in /hermes/waloraweb002/b2497/pow.huzoorbuxcom/htdocs/phpgang/demo/read-your-facebook-stream-php/index.php on line 29

  • Luke Cage

    Hello the script works well but how can i avoid the login button and get directly feeds from FB without clicking on the login link/button?

    • huzoorbux

      You can save access token and use it direct no need to click on buttons all the time.

  • Ajay

    When tried to execute this, I’m getting below error:
    Parse error: syntax error, unexpected ‘class’ (T_CLASS)

  • humble.rumble

    Great, all though i had to add a check on the $data->message and description lines because i always run with display_errors on and error reporting E_ALL. how about the css?

  • Mukesh

    pls provide help me

  • Mukesh

    I’m using your aove code, but i have problem in fetching the feeds, i’m getting empty array.
    whether is due to Facebook extended permission of read_stream, so could you tell me how i can set the permission.
    Your help would be appericiated.
    Plz help me as soon as possible.
    I’m in between the code..

  • kapil karma

    this script is still working……………………..?

  • Nick Green

    I can’t get the script to run I get Parse error: syntax error, unexpected ‘class’ (T_CLASS) in //index.php on line 62
    And line 62 is:
    $content .=”’;

    I really need this to work – I’ve tried a number of PHP and jquery programmes and none of them work always a small error but my level of PHP knowledge prevents me from diagnosing the issue. I just want some thing simple that works and with a good simple explanation of what each of the components do. In your programme I can’t see anywhere to put the url or page ID of the fedd I want to get (where is that).

    • AD

      I think line 62 should read $content .=”; there is an extra ‘ in the example

      • Nick Green

        No that’s not it still getting the same error.

  • Arpit

    i got an error “This authorization code has been used” please help me out

  • Partha Dhar

    hey is it still working ? download not working, can you update a new link ?