Embed facebook page feed on my website
This post explains on how to create Facebook App ID, App secret, Access Token and retrieve facebook feed using facebook Graph API and any server side language. If you are looking for a way to display your facebook page feeds on your feeds then this post would help you.
Different ways of embedding Facebook feed on a website
There are different options to embed Facebook feed on a website depending on how the website is devdeloped.
If your website is setup using a CMS like Wordpress: There would be lot of plugins which can be easily installed and configured. This doesn't require any programming knowledge.
If your website has just few HTML pages without any server side code: Then you can use the Facebook page plugin provided by Facebook. This requires a very basic knowledge of HTML. Detailed steps on the implementation are documented here - Facebook Page Plugin
If your website is developed using a service side language: If your website is developed using some server side language like asp.net, java or PHP and you want to customize the way you want to display the feed on to your website, then this blog post is the one you are looking for.
Creating facebook App ID, App Secret and Access Token
- Login to facebook developers page using your facebook account here – https://developers.facebook.com.
- From the top right drop down click on ‘Add a New App’.
- Select the platform as WWW(Website). In our example we selected WWW, as we are displaying facebook feed on a website.
- Provide some name for your new app and create the App ID. (No – Is this a test version of another app?)
- Once you are finished, select the newly created app from the top right drop down. If your new app is not listed there, refresh the page and check.
- Once your app is opened, you could see your ‘App ID’ and ‘App Secret’. Make a note of these two.
Place your App id and App secret in the URL below and run it in the browser to get the Access Token.
Now your access token is ready and you can use this to get the feed details.
Getting page feed using Access Token, Facebook Graph API
- In the facebook developer page, select your app and go to Tools&Support at the top. Then go to Tools>Graph API Explorer.
- There will a access token field with some value. It is a temporary access token and would expire soon. SO just ignore and don’t use that. Click on ‘Get Token’ and the ‘Get Page Access Token’ and then authorize ‘Graph API Explorer’ to manage your pages.
- There will a FQL Query field below that. You can enter any FQL query and click on submit to check the result of your query. Here we shall build a FQL query to get the facebook page posts feed.
Sample FQL Query: FBPageName/posts?fields=fullpicture,picture,link,message,createdtime&limit=5&accesstoken=YOURACCESSTOKENHERE
The above FQL query gets the below fields of the facebook page posts.
The number of feeds you need can be set by using the parameters ‘limit’. Eg:limit=5 You can even test this link directly from the browser with complete URL as shown below and get the JSON result.
Once you could see the JSON response, you are done with most of the part. Now use any of your favorite server side language and do a GET request to the above URL and get the JSON response. Populate that response in to Html and you could see the facebook posts feed.
Please do share if you like this post! Thanks