Facebook API | Set-2
Prerequisite – Facebook API | Set-1
In 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 download you will see a screen like this-
Now, let’s start with the methods that are provided with the facebook module for Python. We will be discussing the following methods in this article –
This method returns the information as dict associated with the object determined by the object ID.
id: A string that is a unique ID for the particular Object.
agrs(optional): agrs are to be passed as query params.
Get details about the user (In this case, we are using ‘me’ parameter to display details from my account only).
Get Details about a Page (whether the user is the admin of the page or it has permission to manage the page). Before proceeding further Let us first see how to determine the Page ID. Please follow the steps below:
- Click on the down arrow on the right hand side and Navigate to the page for which you want to determine the Page ID.
- Click on the Page Name to go to the page.
- Click on See More Option on the Left hand side on the Page below the Page Profile Picture. After clicking you will see the Option “About”
- Click on “About” Option. You will see the details of your page. Scroll Down to the Bottom and You will find your Page ID.
Now moving to the Python code to find out details of a Page.
This code prints the basic information about the page(about), whether the requesting user is allowed to post anything on this page or not(can_post) and the Category of the Page(category). You can have the complete list of the fields from Page Reference
Example#3: Get details about a Post: message and attachments
Lets first follow the steps below to find the Post ID for a Facebook Post.
- On any Post, click on the date and time mentioned below the user name.
- The post will open in a New Tab.
- Numerals in the last after the last slash (“/”) constitute your Post ID.
Follow the steps below to find the User ID.
- Go to Your Profile Page and right click on your profile Picture. Select the Option “Copy link address”
- Open Notepad and Press Ctrl+V or right click and select Paste option.
- A URL will be Pasted. User ID is mentioned in the end after the “referrer_profile_id”.
Code to find details of a Post.
You can have the complete list of the fields from Post Reference.
This methods returns all objects from the Facebook Social Media Graph as dict. Each ID mentioned in the field list maps to an object.
ids: A list containing IDs for multiple objects/resources
agrs: This is optional and if mentioned need to passed as query parameters.
Example#1: Get the creation time of two different Posts.
Example#2: Get Comments Count of two different Photos.
Follow the steps below to find the Photo ID on Facebook.
- Click on the Photo on Facebook for which you want to identify the Photo ID.
- Find “photo.php” in the Web address area.
- Look for “fbid” followed by a number just after the “photo.php” portion of the URL.
- The number that appears between the “fbid” tag and the “&” symbol is the photo ID number.