Get most recent post from Facebook page, and display on website using new Graph API JavaScript only

12,190
FB.api(
    "/{page-id}/feed",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);

Source: https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed

You could just use the following API call to get only one entry:

/{page-id}/feed?limit=1
Share:
12,190
SomeRandomDeveloper
Author by

SomeRandomDeveloper

Updated on June 04, 2022

Comments

  • SomeRandomDeveloper
    SomeRandomDeveloper almost 2 years

    I'm building a website for a business. The business currently has a Facebook page. On the website i'm creating, i need to display the most recent Facebook post.

    A Google search led me to a depreciated method, and Facebook says now to use the new Graph API, but i'm starting from no Facebook API experience so found it overwhelming and could use some help.

    Here's where i am.

    I'm doing this as a single page site with no server side language, so am only using JavaScript. So far I've got the FB JS SDK script after my body tag, and a app-id setup for my page.

    <script>
        window.fbAsyncInit = function () {
            FB.init({
                appId: 'your-app-id', // except real id
                xfbml: true,
                version: 'v2.4'
            });
        };
    
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    </script>
    

    I have linked my FB app with my FB page. Now i need to display the most recent post on my website.

  • SomeRandomDeveloper
    SomeRandomDeveloper over 8 years
    Thanks for your help. I discovered this only works if i have users logging into the site which they are not. And like Cbroe said i have to use the Page Plugin unfortunately.
  • andyrandy
    andyrandy over 8 years
    that is not correct, and not what CBroe said either. you can use an app access token, without any user login. you just have to use the app token server side.
  • 04FS
    04FS about 5 years
    access_token:'Access token here' - nope, not in client-side code, that is a very big no-no.
  • Srinivasan N
    Srinivasan N about 5 years
    Access token provided from fb developer account is big. I have given code to get both post from Wall and post from page we manage in fb.