Facebook's graph API
This is a very short article and it explains Facebook's Graph Application Programming Interface (API) and how to read data from the Social Graph using HTTP's GET method. First of all we should understand what an API is and how it works.
An API works like a web site, we can make requests to an API and get a response back over the HyperText Transfer Protocol (HTTP). There are various kinds of APIs (Twitter's API, Google's API and Facebook's API and so on).
REST API
Representational State Transfer (REST) works the same as a website does, we can make a call from a client to a server over HTTP protocol and get a response back.
Graph API
REST API is the original API for developing on the Facebook platform but a few years ago they decided to go in a new direction and launched the Graph API. Using this Graph API we can read data from and write data to Facebook's Social Graph. It's based on the HTTP protocol. We can do many things with the Graph API, we can request data, post new stories, upload photos and so on. Let's see how Facebook's Graph API works.
This is the drawing of Social Graph. Here dots/nodes represent people and the line between the dots/nodes represent a relationship between them.
Getting data from Facebook Social Graph
As we all know Facebook's domain name is facebook.
Let us now take any Facebook page/User/Group to understand the Graph API. Here I will choose C# Corner's page CsharpCorner.
Now let's replace www with graph in the preceding URL.
So it should be like CSharpCorner Graph and press Enter.
We can also see a person or group name instead of Page name.
And here is what happened, we got the data from the Graph API in JavaScript Object Notation (JSON) format. This data is well structured and arranged in key and value pair format.
We can also request only specific fields if we want, you can see that in the following screenshot. I was trying to request some fields like ID, Name, Likes (Total Page Likes), and Location.
You can check other fields (like gender, hometown, relationship_status, bio, quotes, political, birthday and so on).
Fetching data for someone (by UserID)
Type https://graph.facebook.com/{user_id}

It gives only public information about me and my profile. We can also see someone's recent posts and their feed using.
https://graph.facebook.com/{user_id}/feed
Some requests require an Access Token and in that case it will return an OAuthException.


ParthaPosted Jul 23, 2019, 8:32 PM EDT
Why am I getting access token required when I try to access https://graph.facebook.com/CsharpCorner { "error": { "message": "An access token is required to request this resource.", "type": "OAuthException", "code": 104, "fbtrace_id": "AP3Zwt9yCVMNYKR6DhZrTM5" } }
Santhakumar MunuswamyPosted Jun 14, 2015, 10:51 AM EDT
Thanks for nice one
Rahul Kumar SaxenaTOP 100Posted Mar 15, 2015, 2:42 AM EDT
Good Show
Gowtham RajamanickamTOP 100Posted Mar 14, 2015, 12:45 AM EDT
Good..
RakeshPosted Mar 5, 2015, 8:26 AM EST
Hi Sam, Here the term APIs can mean many different things. Sometimes it means hardware APIs, or the Java API or various other technical incarnations. Right now in this article the term API means web API or an API built using REST, running on the same infrastructure the World Wide Web runs on
Sam HobbsPosted Mar 5, 2015, 8:17 AM EST
I am confused. It uses HTTP so is it a web service or something like that? Most APIs only work within a system, not across systems. So Twitter's , Google's and Facebook's APIs are not representative of typical APIs. Since the Facebook Graph API works across systems I wonder why it is called an API.
Dinesh BeniwalTOP 10Posted Mar 5, 2015, 7:11 AM EST
Thanks for sharing Rakesh.
RakeshPosted Mar 5, 2015, 6:28 AM EST
thanks Sourabh Somani
Sourabh SomaniTOP 100Posted Mar 5, 2015, 6:23 AM EST
Rakesh : Gr8 work :)
RakeshPosted Mar 5, 2015, 5:40 AM EST
thank you :)
Vithal WadjeTOP 100Posted Mar 5, 2015, 5:01 AM EST
nice work,keep it up