First impression about Facebook's Graph API
Tags: react, discuss, review, api
Published: 2018-02-25 17:47:13

---
title: "First impression about Facebook's Graph API"
published: true
description: Discovering Facebook's Graph API
tags: React,Discuss,Review, API
---

![Doggo Studying](https://thepracticaldev.s3.amazonaws.com/i/iuy7epdgln1vx0pov33c.jpg)


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:
```javascript
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});
       });
```
Displaying the results in UI:
```javascript
   {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>

             );
                  })}
```


[Twitter's API](https://developer.twitter.com/en/docs/tweets/post-and-engage/overview) 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](https://thepracticaldev.s3.amazonaws.com/i/i9hx2aeodb2utpgwkxig.PNG)

Another advantages of Facebook's Graph API, is the big [documentation](https://developers.facebook.com/docs/graph-api) they have and the tool that they give us called ["Graph API Explorer"](https://developers.facebook.com/tools/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](https://github.com/jjsantos2012/Fetch-Data-From-Social-Media) 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...