In today's world we have lot of data and awesome plotting tools like plotly. One of the best source of data is Facebook. Since we have registered as a user on facebook, uptill now we have gathered a lot of data. Here we are going to exploit these facebook data to give insightful graphs. How? Lets see
What we are actually going to do??
We will code a simple app in order to determine our best social buddy. The person in our friendslist who has most likes on our facebook wallpost will be our best social buddy.
In more detailed sense, this code will iterate through each of your wall post and put a counter to every friend who has liked your facebook post. The one with maximum count will be your best social friend.
After converting data into insigthful information, we will plot this information using plotly API to give visually attractive results.
Step 1: Requirements
Following are the requirements of this instructable:
-- Python (Any version will do above 2.7. Here we will be using 2.7.3)
-- A facebook account
-- A plotly account (Its free to get one)
-- A computer running Windows, Linux or Mac OS (In this instructable, we are going to work with Windows) with Internet connecton.
Step 2: Installing Python and Pip
Python is the most user friendly programming language. It would lets us code in hours what other programming languages would take days to code.
Assuming everyone is new to python I will go through each and every step of installing python and its dependencies to get our app running.
1) Find a suitable package of python to install on your system here. In this instructable I have used Python 2.7.6 for windows. After downloading, install python.
2) Next we need to install 'pip'. 'pip' is a tool for installing and managing python packages. We need 'pip' to install two packages(requests and plotly).
To install pip, download 'get-pip.py' file attached here.
Copy the get-pip.py file to "C:\Python27".
("C:\Python27" directory may vary according to version installed on your PC)
3) Open 'Command prompt' in windows. Once in command prompt, enter the following commands without quotes :
(cd is a navigation command that lets you navigate Windows file system using command prompt)
(According to version of python installed on your system, change 'python27' to directory name as in your PC)
After such commands, 'pip' will be installed in your systems.
Step 3: Installing Dependencies
After installing 'pip' we need to install dependencies that our code needs.We will be installing two modules, 'requests' and 'plotly'
If you have successfully completed previous step, you are in C:\Python27 directory.
Type the following commands(without quotes) in command prompt itself to install dependencies.
(This will take you to C:\python27\scripts directory)
"pip install requests"
(Wait while requests is being installed)
"pip install plotly"
(Wait while plotly module is being installed)
You have successfully completed the installation part.
Now lets move to some real code.
Step 4: Code
Attached is the python code of our app. Download it.
Open 'Python(IDLE)' from Start menu. Open the code you just downloaded. It will look as shown in screenshot attached.
Lets analyze the code.
We just need to input values under 'User Information block' and rest code is just fine.
What the code does?
The code will iterate through each of your wall post and keep a track of friends who liked your wallpost. It will collect all 'likes' and generate information about which friend has given most number of likes.
Step 5: Facebook API
To access Facebook data we will need some permissions from Facebook. Facebook graphi API comes to our rescue. Graph API is for facebook developers to get facebook data using code.
Follow these simple steps.
1) Log in to your facebook account.
2) Click here. It will redirect you to Graph API Explorer.
3) Click 'Get Access Token' as shown in pic.
4) Check all the permissions needed in all three tabs as shown in attached screenshots.
5) Copy the generated access token.
6) Paste it in code under User Information for 'TOKEN' variable.(Put the token under single quotes)
Now we move forward for getting plotly user information.
Step 6: Plotly
Plotly is an data analysis and graphing tool. It provides great support for most of programming languages and has nice API to plot real time graphs.
Follow these steps to use plotly :
1) Get a plotly account. Its free and quick to set up.
2) After setting up your account and logging in, click here.
3) Copy your User name and User API key as shown in figure attached.
4) Paste this User name and User API key under User Information block for user_name and user_name and user_api.
Now its time to visualize the results.
Step 7: Visualize
After everything is up, run the code by pressing F5 or from 'Run' menu.
A browser will open showing you a bar chart resembling to one shown above.
See who are your best social buddies.
Get creative with your idea.
This is just one application of how you could use facebook and plotly. Get creative with your idea and show world what you could do with these great tools.
vgokani made it!