Peter Chang

@peterchang_82818

[GraphAPI] Fetch public Facebook page’s feed by GraphAPI in 3 Step

This article is out of date since 2018, sorry about that.

This is a example to show how easy to query data from public Facebook page by GraphAPI.

I am going to take my favourite page, LadBible as the example, and intend to get the information below:
1. List of Posts of a page 
2. Detail of single Post

1. Creating an APP

To use GraphAPI, it is required to call with valid access token, to get valid access token, it is required to have APP_ID and APP_secret of a Facebook Application.

Go to the developer portal and follow the instruction, to create a APP which provide you APP_ID and APP_secret:

2. GET: access_token

GraphAPI provides a handful way to get access_token, by sending a HTTP GET request with parameters YOUR_APP_ID and YOUR_SECRET:

GET https://graph.facebook.com/oauth/access_token?client_id={YOUR_APP_ID}&client_secret={YOUR_SECRET}&grant_type=client_credentials

Paste it into browser:

3. GET: List of feed

Since we got the access_token by the response in Step2, which is used as parameter for any graphAPI request.

To get the Facebook Page’s feeds, we need to tell GraphAPI which the ID of the page, where we can find from the page URL:

Get the pageId of LadBible, assemble it into the URL below:

GET https://graph.facebook.com/v2.9/LADbible/posts?access_token={ACCESS_TOKEN}

Paste it into browser:

Things you may wanna know

Below is the note where you can go deeper about GraphAPI. Things becomes so easy of what Facebook team built for the developers, making a public page crawler, or users behavior data analytic are just a matter of few click.

1. ExplorerDocument

GraphAPI explorer is the API playground, I would say that it is the best API documenting and troubleshooting tool I have even used, there is simple user interface, RESTful URL design and immediate HTTP response result just within a click. I don’t even need to write a line of code, to ensure I am doing it right.

I use to test the API URL on explorer first, then assemble in to my code.

2. To get action data of a post


GET
https://graph.facebook.com/v2.9/{POST_ID}/reactions?access_token={ACCESS_TOKEN}

Reference:

https://developers.facebook.com/docs/graph-api/reference

https://developers.facebook.com/tools/explorer/

More by Peter Chang

Topics of interest

More Related Stories