What’s good about the Facebook API ???

Tram Ho

1. Introduction

1.1. What is the API ??

  • API (Application Programming Interface) is an application programming interface, it is a method to connect to libraries and other applications. Window, Google, Twitter … all have their own APIs.
  • With this API it is possible to create applications using features or data existing on their server. => In a nutshell it is like a library that you can use through requests

1.2. What is Facebook API ??

  • Facebook API is a platform provided by Facebook for application writers to easily create applications and ensure application writers do not interfere too deeply into Facebook’s system.
  • Through the Facebook API, we can get information about users such as personal information, profile photos … if given permission to access the personal page.
  • Facebook sends a POST method to the Facebook API server. It includes a number of request parameters such as the application’s api_key, and the session_key of the user making the request. In addition, Facebook also adds the fb_sig parameter to notify the application of making a request. This way all API calls are guaranteed, Facebook can verify requests sent from an approved application.

2. Facebook Graph API

2.1. Define

  • The word Graph translates to the graph, so the Facebook Graph API is the way to get data in and out of Facebook’s social graph. You can use it to query data, submit new stories, upload pictures, and a host of other tasks an app can do.
  • It includes:
    • node: Things that appear on facebook have interactions such as photos, posts …
    • edge: connections, relationships between it.
    • field: its information.

The Graph API is HTTP based, so works with any language that has an HTTP library, like cURL, urllib – You will get data through http requests.

Illustration

2.2. Access Facebook’s Graph API interface

  • First you visit https://developers.facebook.com/
  • Then you have to create a facebook application , otherwise you will not be able to use the api. (How to create, you guys google offline).
  • Go to More -> Tool -> Graph API Explorer, you will get the interface below.

  • The main components:
  1. Where to grant access to your data, you can specify API permissions
  2. Create Access_Token to access API
  3. Where to send the request
  4. Enter the information you want to retrieve
  5. Where to display data (data is displayed as json)

Example: I want to get the user_id and name, I will enter the number 4, the data will be returned at number 5

You can also retrieve the posts and reactions you have dropped by importing them (you only have access to allowed fields in # 1).

2.3. Manually use the Graph API

  • Attention:
    • your-user-id : user id, or you can type me .
    • field : the field you want to retrieve
    • your-user-access-token : Access_Token that you got in the interface earlier.
  • For example: I will get the userId information, name, gender, date of birth and count how many friends I have.

3. Conclusion

So I have synthesized “dew mist” what is the most basic of facebook graph api, if I have time I will write another post using facebook api in the code.

If the article is flawed, please sympathize and give your suggestions to make other articles better. Thank you very much for viewing the article

4. References


Share the news now

Source : Viblo