In this series of articles, we will cover the details about Facebook API in depth. We will learn what setup we need to use the API and how to make everything get going for the API to work. So, Let's skip the Introduction and Jump on to the details of the API.
There are 2 sets of API Available from the Facebook Platform -
- Graph API
- Marketing API
Let's first start with the
Graph API.
Graph API is the primary way to access means read and write data on the social media Facebook social graph. We will first discuss the overview of the Graph API, proceeding to the setup, we will then finally see how to use Graph API Explorer for reading and writing data on Facebook Social Graph.
Graph API is basically composed of 3 components:
- node: These are individual objects such as User, Page, Photo or a Comment. We use Nodes to gather data about individual Objects.
- edges: These represents the connections between collections of objects and single object. Edges are used to publish single objects to the collection of objects or to get collections of objects that are connected to a single object. Suppose we consider a Photo posted on Facebook Profile of an Individual. Now the comments associated with this Photo refers to the collection of Objects that are associated with the single Object that is Photo in our case.
- fields: These represents the data or Information about an object. User Age, Date of Birth are examples of fields that are associated with a node User. fields are used to specify the data that we want to include in a response.
Since Graph API is HTTP based, so it works with any Language that has HTTP Based Library like curl, urllib etc. All request are passed to the
graph.facebook.com
host URL. Exception to this is Video upload which uses the URL:
graph-video.facebook.com
.
Since Nodes are Individual Objects on Facebook. So each node has an associated unique Id. Every User, Page or Photo has a unique Id associated with it. Before proceeding further let's first discuss Access Tokens and how to generate one to use for querying data from Facebook Social Graph.
Access Token here majorly serves 2 purposes:
- It allows the app to access a User's Data without requiring User's credentials.
- It allows the server to identify who is using the app and to determine accordingly what functions that user is permitted to do.
Access Tokens conform to
OAuth 2.0 Protocol
. This means Access Tokens implement both Authentication and Authorization, as we have discussed in the
last article.
Here, we have 4 types of Access Tokens:
- User Access Token: This is the most commonly used access token, needed when an app calls an API to read, modify or write data on specific person's Facebook Page. This is achieved through a login dialog where a person is required to permit the app to obtain access token
- App Access Token: This token is obtained using server to server call. This token is used to read, modify the app settings.
- Page Access Token: Once you have the User Access Token you obtain the Page Access Token via the Graph API. The procedure is very simple, first, obtain the User Access Token and then ask for the manage_posts permission. You will get your Page Access Token. This token is very much similar to the User Access Token, except for the case where it provides permission to the API that read, modify or write data to a Facebook Page.
- Client Token: Client token is an identifier that can be embedded in native mobile binaries or desktop app. It is used to access app-level APIs.
Follow the steps below to generate Access Token:
- Go to the link Facebook Developers and in the right most corner you will find an option to "Login". If you are not an existing customer create a new account by clicking on the "Login" option and then clicking on the "Create New Account" button appearing below the Login button.
- After Successful login or a successful account creation you will get previous screen with "My Apps" option at the place of Login.

- Go to "My Apps" drop down in the right most corner and select "Add New App" . Enter Display Name and Contact Email and click on "Create App ID".
- After entering the required information, you will see the Home Screen of your Facebook Developer Account, with App ID mentioned on the top.
- Click on the "Tools" Drop Down and from the list click on first option i.e."Graph API Explorer" Option.
- On the Graph API Explorer window click on the "Get Token" button. From the drop down list, click on "Get User Access Token".

- On clicking on the "Get User Access Token", you will get a huge list of User permissions grouped under 3 categories: User Data Permissions, Events, Groups and Pages and Other Permissions. You can skip the permissions that you don't want. After making the selection, click on "Get Access Token". You will get a screen for Login review.

- After successful completion of above steps you will get your User Access Token.
- Now once again click on the "Tools" Drop Down on the same page and now this time click on the second option "Access Token Debugger".
Note: Before clicking on Access Token Debugger Option, Copy the User Access Token generated in the previous step.
- Now Paste the user access token in the dialog box stating Enter an Access Token to debug and click on the "Debug" Button.
- After clicking on Debug Option You will see some information about your user access token. Below those details, there is an option to "Extend Access Token". Click on this button. You will be asked to enter your Facebook Login Password and You are done!!!. The token that was about to expire in 2 hours will have life increased to 2 months. This extra step ensures that your access token does not expire in every 2 hours.
In the next article, we will be discussing how the User Access Token can be used for accessing different types of information from the Facebook Social Graph.
References:
- https://developers.facebook.com/docs/facebook-login/access-tokens
- https://developers.facebook.com/docs/graph-api/overview/
Similar Reads
Facebook API | Set-4
Prerequisites: Facebook API Set-1, Set-2, Set-3 In this article we will be discussing 3 methods : put_object put_like put_comment put_object: Writes the mentioned object to the Facebook Social Graph connected to the given parent. Parameters: parent_object: A string specifying the parent of the new o
2 min read
Facebook API | Set-3
Prerequisite: Facebook API | Set-1, Set-2 In this article we will be discussing three methods: search get_connections get_allconnections search method: The valid value types are place and placetopic. Parameters: id: It is a string containing a valid value. args: This is optional and they need to pas
3 min read
Facebook API | Set-2
Prerequisite - Facebook API | Set-1In this article, we will be discussing the implementation details of the Facebook API for Python Platform. Let's begin with downloading Facebook Client for Python. Use following python command to download Facebook Client- pip install facebook-sdk Upon successful do
4 min read
Social Network API
Social media websites were initially designed to confined user experience within four walls of their web page. However, to increase their user base and to expand beyond only desktop accessible websites, these social networks started developing API. Those who are into social media programming must be
4 min read
Creating Phishing page of a website
Prerequisite - Phishing Phishing is a type of social engineering attack of tricking an individual to enter the sensitive information like usernames, passwords and credit card details. It can be done by any individual with a mere basic requirement of Kali Linux (or any other Linux Distribution). Step
2 min read
Privacy and Security in online social media
Social media is not a new term for us. Our daily life is incomplete, or we can say we human beings survive on food, water, air and social media. We are dependent to such an extent that we tend to share every bit of information about us on social platform. But stop for a minute and think, Are we real
7 min read
Ethical hacking - Practical Phishing
Phishing : It is a way to gather personal information using deceptive e-mails and websites. It is a very regular practice done in every field, it can be done by professional hackers or a normal person also. It can be done through a simple trap link or a fully prepared fake account on Facebook or on
3 min read
Futuristic Solution to Privacy and Security in online social media
Social media has become an important part of our lives. This has led to rising of lots of messaging apps like Messenger, WhatsApp and so on. These are great for communication and have a lot of features for people to communicate effectively. On one side there is an uprising advent of technology in pe
4 min read
Send message to FB friend using Python
The power of Python comes because of the large number of modules it has. This time we are going to use one of those. Every one of us, one time or another, has a wish of the message (or spamming -.-) our Facebook friend. This is a program that can do something similar. So without further delay, letâs
3 min read
How to like multiple posts on facebook news feed automatically using JavaScript ?
In this article, we are going to learn how to like multiple posts automatically on the Facebook news feed. Many a time we waste too much time liking all the posts in our news feeds. So this script will help to reduce our time and effort by automating this task. Approach: Make a variable post that po
2 min read