Facebook Analytics
Facebook Analytics
Module-2
Contents
• Introduction to facebook app
• Understanding Graph API
• Registering Web App
• Accessing facebook user profile via API
• Accessing friends count via API
• Accessing posts via API
• Accessing detailed posts via API
• Performing statistical analysis
• Posts word cloud
Facebook
• Facebook is a social media platform founded by Mark Zuckerberg and his
college roommates Eduardo Saverin, Andrew McCollum, Dustin Moskovitz,
and Chris Hughes.
• It was launched on February 4, 2004, initially as "The Facebook" for Harvard
University students before expanding to other colleges and eventually the
general public.
• Facebook allows users to create profiles, share posts, photos, and videos,
connect with friends and family, join groups, and follow pages of interest.
• Over the years, Facebook has grown into one of the largest and most influential
social media platforms globally, with billions of active users.
Facebook Graph API
The Graph API is the primary way to get data into and out of the Facebook platform.
It's an HTTP-based API that apps can use to programmatically query data, post new
stories, manage ads, upload photos, and perform a wide variety of other tasks.
The Graph API is named after the idea of a "social graph" — a representation of the
information on Facebook.
Facebook Graph API is the core component of the FB platform.
It enables the interaction of third parties with FB.
As name suggests it offers a consistent graph like view of data.
Representing the objects and the connections between data.
The different platform components allow developers to access FB data and integrate
FB functionalities into third-party applications.
Registering your app
The access to the FB API is offered through a registered web app.
Developers have to register their app in order to obtain the credentials needed to consume the
Graph API.
In order to access user profile information, as well as the information about their interactions with
other objects for example: pages, places and so on. Your app must obtain an access token with the
appropriate permissions.
Token is a unique to the user-app combination and handles the permissions that the user has
granted to the application.
An access token is an opaque string that identifies a user, app, or Page and can be used by the app
to make graph API calls.
The token includes information about when the token will expire and which app generated the
token.
Because of privacy checks, the majority of API calls on Meta apps need to include an access
token.
• There are different types of access tokens to support different use case and a number of methods to
obtain an access token.
ACCESSING THE FACEBOOK GRAPH API WITH
PYTHON:
1. Once the app details are defined, we can programmatically access the Facebook Graph API via Python.
3. Implementing our own client using the requests library could be an interesting exercise in order to
understand the peculiarities of the API, but fortunately, there are already some options out there to simplify
the process.
4. For our examples, we are going use facebook-sdk, also based on the requests library, which provides an
easy-to-use interface to get data from and to a web service.
• We can install the library using pip from our virtual environment as follows:
• OR
A Post object has even more attributes than the ones represented in the above table. A complete list of attributes
is given in the official documentation (https://developers.facebook.com/docs/graph-api/reference/v2.5 /post),
where the complexity of this object is even clearer.
Attribute name Description
status_type String representing the type of post for example added_photos or shared_story
updated_time String with the date of last modification in the ISO 8601 format
properties List of properties of any attached video for example ,length of the video
MINING YOUR POSTS:
MINING YOUR POSTS:
• 1. Downloading your own posts published by the authenticated users.
• 2. The facebook_get_my_posts.py script connects to the Graph API and gets the list of posts published by the
authenticated user “me”.