0% found this document useful (0 votes)
4 views30 pages

Facebook Analytics

The document provides an overview of Facebook analytics, focusing on the Facebook Graph API, which allows developers to access and manipulate Facebook data programmatically. It details the process of registering a web app, obtaining access tokens, and using Python to interact with the API to access user profiles, friends, and posts. Additionally, it explains the structure of posts and how to download posts published by authenticated users.

Uploaded by

ajithkumarposa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Facebook Analytics

The document provides an overview of Facebook analytics, focusing on the Facebook Graph API, which allows developers to access and manipulate Facebook data programmatically. It details the process of registering a web app, obtaining access tokens, and using Python to interact with the API to access user profiles, friends, and posts. Additionally, it explains the structure of posts and how to download posts published by authenticated users.

Uploaded by

ajithkumarposa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

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.

 As a FB user, you explicitly have to register as a developer in order to create apps.

 Account has to be verified via either by mobile phone or credit card.

 From Facebook Developers website: https://developers.facebook.com

1. Login to your FB account with phone number.

2. After logging in.


• In developer’s website click on MyApps option as shown below:
• After clicking on the My Apps you will get the below page.
• Click on Create App button.

• After clicking on the Create App following page will be displayed.


• Once after authenticating the and requesting data from FB the following page will be
displayed.
• After clicking on the next button the following page will be displayed and provide the app
name as per you wish and click on create app button.
• After creating an app the following page will be displayed.
• Then point the cursor on tools and click on Graph API Explorer.
• 11. After clicking on Graph API Explorer the following page will be displayed and
then Click on Generate Access Token button and get the token.
• Adding user data permission to the API in order to access the facebook data and perform
analysis.
• Token :
EAAE1CHr13VEBOxP8dHGGm1ahitDKh4YxT2OfbVZBJx1rrpaOUIxcSxpxKWie6KZAtHtEdeJE03KZB9
3JjsTb560uwOjPtfSXaLxWhfhW6ZAtjnTdGwoE4iZBfNG6vDdcZBklZBMr487UiqqZCoHgq2njFC9YN1R
JHZAwDWNFr1FDRelu7j4LGhhQmcDcL1elQGRGxUuAax9v0UMscpfMJULrlHx1jEc3niU1OoLof03bINj
NuhgcvnNr66RbKMAOjjPhLc1uFRgZDZD

• An access token is a unique alphanumeric string that serves as a


credential, granting an application permission to access specific user
data on Facebook's platform, such as retrieving information.
• After adding permissions, all the permissions will be listed under “USER ACESS LINK”
dropdown in the API explorer.
The Graph API supports the following user data permissions in order to access the facebook information:
• user_friends
• user_posts
• user_gender
• user_link
• user_age_range
• email
• public_profile
• user_birthday
• user_hometown
• user_likes
• user_location
• user_photos
• user_posts
• user_videos
• user_payment_tokens
• Authentication and security:

 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.

2. Facebook doesn’t provide an official client for 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.

5. In PyPI latest version of library is available which fully supports Python 3.


ACCESSING THE FACEBOOK GRAPH API WITH
PYTHON:

• We can install the library using pip from our virtual environment as follows:

• $ pip install facebook-sdk

• OR

• pip install facebook-sdk


1. FACEBOOK PROFILE
• The following script facrbook_my_profile.py, connects the Graph API and queries for the profile of the
authenticated user.
1. FACEBOOK PROFILE
python facebook_my_profile.py
The output of the above script shown below:
2. GETTING FACEBOOK FRIENDS:
2. GETTING FACEBOOK FRIENDS:
• The following is a sample output:
MINING YOUR POSTS:
• Structure of a post:

A post is complex object as it can essentially be any piece of content


that a user decides to publish.

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

id String representing a unique identifier


application The App object with information about the app used to publish this post

status_type String representing the type of post for example added_photos or shared_story

message String representing the status message of the post


created_time String with the date the post has been published in the ISO 8601 format.

updated_time String with the date of last modification in the ISO 8601 format

message_tags List of profiles tagged in the message

from Profile of profiles tagged in the message


to List of profiles mentioned or targeted in the post
place Location information attached to the post
privacy Object with the privacy settings of the post
story_tags Same as message_tags

with_tags List of profiles tagged as being the author of the post

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”.

• 3. The posts are saved in the my_posts. jsonl file.

• 4. Here we make of JSON lines format.


MINING YOUR POSTS:
This example of a JSON document representing one of the download posts:

You might also like