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});
});
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>
);
})}
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.
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...
Top comments (3)
I've been working now for ~2y with their API for work and I agree with the mentioned advantage.
It's very useful to be able to quickly test something with a simple URL call in browser or cURL, the documentation is actually really intuitive after working a bit with it.
They provide really good examples and after working on some projects with the Google API I actually started missing the FB structure.
I still find sometimes, but rare, functions that are not or not well documented but because of the consistent format I'm always able to figure out how it should be used.
They actually have different ids for some objects, for example you can have a FB user id, app scoped user id, business scoped user id and it's a bit confusing in the beginning as they don't provide matchings as far as I know.
But I actually don't think it's something you will come across when not working with the Business side.
I actually really like their API & documentation and and it's very simple compared to other APIs to quickly create something useful
Great article! :)
Cheers
I've been trying Graph the last days, to scrape data from FB pages, like news pages and so, but when I try getting the feed posts of a page, it skips so many posts! And the further I go in the past, the less posts I get returned. Is this normal? Is someone facing the same problem?
Hello, am trying to use Graph API to fetch events but am not sure how,
Here is the post I made
I will like if you could help me.