First impression about Facebook's Graph API

Juan De los santos - Feb 25 '18 - - Dev Community

Doggo Studying

I have been checking the Facebook´s Graph API for a couple days, and here I have my first impressions about it.

For those who doesn't know about Facebook's Graph API, they defined it as "the primary way to get data in and out of Facebook's social graph" or "The core of Facebook Platform, enabling developers to read from and write data into Facebook".

After a quick review of the documentation, I just can say that the learning curve is considerably lower than other services of this kind such as Twitter's API.

One of biggest advantages of Facebook's Graph API against others (At least from my perspective), is that you don't need any special code structucture to get most of the information from their API; You just have to follow the regular process to consume a JSON response...

Fetching the data from Facebook's Graph API:

fetch("https://graph.facebook.com/v2.9/HereGoesThePageID/posts?access_token=HereGoesYourToken")
       .then(response => response.json())
       .then(json => {
         console.log(json);
         this.setState({data: json});
       });
Enter fullscreen mode Exit fullscreen mode

Displaying the results in UI:

   {this.state.data['data'].map((item) => {
               return (
                 <div key={item.id}>
                 <Card>
                    <Row>
                          <Col>
                            <h6>{item.story}</h6>
                            <h6>{item.message}</h6>
                          </Col>
                    </Row>
                </Card>
                 </div>

             );
                  })}
Enter fullscreen mode Exit fullscreen mode

Twitter's API used to work in that way also but a couple years ago they added a new level of security implementing "Oauth", that makes the requests and responses more "secure" but that increase the learning curve and takes you more time to handle the API properly. Facebook's Graph API also has secure requests just like Oauth in Twitter, but in this case it just apply for some special request like when you try to get data considered as private by the owner or the Facebook's polices.

Graph API Explorer

Another advantages of Facebook's Graph API, is the big documentation they have and the tool that they give us called "Graph API Explorer" to make requests in their own "console", so it make it easy for us to understand the bunch of criterias we have available, and help us to determine what we need before start consuming the API itself.


I made a simple demo in github of how to fetch the Posts from a Facebook Page, using Facebook's Graph API and Javascript (ReactJS), so there you can find whole code of the examples shown above.

Have you used Facebook's Graph API? Let me know how was your experience and why do you use it...

. . . . . . . . . . . . .
Terabox Video Player