Tags

, , , , , ,

Hello All !

In this tutorial, I will help learners to learn about “Data Mining on Facebook Data”.

First of all you have to get an access token from your facebook account. This token will allow you to access the data from your account on FB.

Here is how to get it:

Step 1:

Go to https://developers.facebook.com/tools/explorer

Step 2:

When you see the Graph API Explorer as below, select from the dropdown menu and change API Version to “Unversioned“.

FB Access Token

Step 3:

Click on “Get Access Token” button and you will see the below pop-up window. Under “User Data Permissions” tab, select all the options (by clicking on check boxes). Do not click on any other button but you should now click on “Friends Data Permissions” tab.

User Data Permissions

Step 4:

Similar to step 3, click on all the options and then click on “Extended permissions

Friends Data Permissions

Step 5:

Do the same with “Extended Permissions” as in step 3 and 4:

Extended Permissions

Click on “Get Access Token” and FB then will return you a system generated code.

Step 6:

Copy this Access Token Code:

Access Token Code

We are now good to go.

####################################################

Some basic “FB Data analysis using R”

####################################################

# load required packages (please install if not already installed)
> library(Rfacebook)

> library(Rook)

> require(RCurl)

> require(rjson)
> access_token = "PASTE YOUR TOKEN CODE WITHIN BLOCK QUOTES"

> myFB = getUsers("me", token = access_token)

> myFriends = getFriends(access_token, simplify=FALSE)

> myFriends_info <- getUsers(myFriends$id, token=access_token, private_info=TRUE)

> table(myFriends_info$relationship_status)


## If above is not working then you need to follow the following steps

1. Go to "developer.facebook.com/apps" website using your login
2. Create a new App
3. In settings, click +Add Plateform and add the following address:
http://localhost:1410/   and save it.
4. Run the following code as below in R and hit enter key to proceed with 
authrization process.

fb5

fb7

fb6

fb8

fb3

fb4


# Setting default working directory
# setwd("E:/RProjects/Facebook")

# load required packages (please install if not already installed)
library(Rfacebook)
library(Rook)
require(RCurl)
require(rjson)

fb_oauth <- fbOAuth(app_id = "Your FB App ID", 
app_secret = "Your FB App Secret", extended_permissions = TRUE)

# Saving authorization file on the computer (in default working directory)
save(fboauth, file="fboauth")

# Loading authorization file from the computer (from default working directory)
load("fboauth")

# Getting info about self (as user)
myFB <- getUsers("me", token = fboauth)

# Summarizing info
myFB

myFB$name
head(myFB$id)

# Collecting info about pages I liked
mylikes <- getLikes(user = "me", token = fboauth)

# Viewing a few of the pages I liked
head(mylikes)



##  output....
 
##      Engaged       In a relationship      In an open relationship 
##       3                       6                       2 
##      It's complicated     Married               Separated 
##       3                      68                       1 
##      Single 
##       87

####################################################

Some More…

####################################################

# Retrieve list of mutual friendships and return the list for the network (using either Edge List or Adjacency Matrix)

> myFriendsNetwork1 = getNetwork(access_token, format = "edgelist", verbose = TRUE)
// 
> myFriendsNetwork1
## Sample Output of Friends in my network in common with others (within my network)
##         [,1]                           [,2]                          
##    [1,] "Silky Prabhakar Ramphal"      "Vivek Saxena"                
##    [2,] "Silky Prabhakar Ramphal"      "Nidhi Negi"                  
##    [3,] "Silky Prabhakar Ramphal"      "Priya Garg"                  
##    [4,] "Silky Prabhakar Ramphal"      "Divyanka Goyal"              
##    [5,] "Silky Prabhakar Ramphal"      "Rabi Narayan Satpathy"       
##    [6,] "Silky Prabhakar Ramphal"      "Rajan Girdhar"               
##    [7,] "Silky Prabhakar Ramphal"      "Gurwinderpal Singh"          
##    [8,] "Silky Prabhakar Ramphal"      "Akhlak Khan"                 
##    [9,] "Silky Prabhakar Ramphal"      "Ankush Sharma Anki"          
##   [10,] "Silky Prabhakar Ramphal"      "Minni Khatana"               
##   [11,] "Silky Prabhakar Ramphal"      "Amandeep Kaur"               
##   [12,] "Silky Prabhakar Ramphal"      "Neena Malhotra"              
##   [13,] "Silky Prabhakar Ramphal"      "Ravneet Garcha Bhatti"       
##   [14,] "Silky Prabhakar Ramphal"      "Pranav Ranjan"               
##   [15,] "Silky Prabhakar Ramphal"      "Deepak Singh Bhardwaj"       
##   [16,] "Silky Prabhakar Ramphal"      "Sharma Sourabh"              
##   [17,] "Vivek Saxena"                 "Silky Prabhakar Ramphal"     
##   [18,] "Vivek Saxena"                 "Kumar Saurabh"               
##   [19,] "Vivek Saxena"                 "Neha Shandilya"              
##   [20,] "Vivek Saxena"                 "Yogita S Doda"               
##   [21,] "Vivek Saxena"                 "Raj Sethi"                   
##   [22,] "Vivek Saxena"                 "Mandip Saini"                
##   [23,] "Vivek Saxena"                 "Nidhi Negi"                  
##   [24,] "Vivek Saxena"                 "Sakshi Sharma"               
##   [25,] "Vivek Saxena"                 "Anand Mani Singh"            
##   [26,] "Vivek Saxena"                 "Prince Vohra"                
##   [27,] "Vivek Saxena"                 "Ripsy Midha"                 
##   [28,] "Vivek Saxena"                 "Manoj Goyal"                 
##   [29,] "Vivek Saxena"                 "Rohit Sharma"                
##   [30,] "Vivek Saxena"                 "Priya Garg"                  
##   [31,] "Vivek Saxena"                 "Rampal Shikha"               
##   [32,] "Vivek Saxena"                 "Richa Kunal Jolly"           
##   [33,] "Vivek Saxena"                 "Vimal Saini"                 
##   [34,] "Vivek Saxena"                 "Nikhil Wadhwa"               
##   [35,] "Vivek Saxena"                 "Tushinder Preet Kaur Bhullar"
##   [36,] "Vivek Saxena"                 "Shammi Dhiman"               
##   [37,] "Vivek Saxena"                 "Pooja Garg"                  
##   [38,] "Vivek Saxena"                 "Vikas Anand"                 
##   [39,] "Vivek Saxena"                 "Ajay Singh Chandel"          
##   [40,] "Vivek Saxena"                 "Aman Arora"                  
##   [41,] "Vivek Saxena"                 "Karan Sood"                  
##   [42,] "Vivek Saxena"                 "Sardar Manpreet Singh"       
##   [43,] "Vivek Saxena"                 "Rabi Narayan Satpathy"       
##   [44,] "Vivek Saxena"                 "Ujjwal Kumar Ojha"           
##   [45,] "Vivek Saxena"                 "Priya Sharma"                
##   [46,] "Vivek Saxena"                 "Tarun Gupta"                 
##   [47,] "Vivek Saxena"                 "Dal Jeet"                    
##   [48,] "Vivek Saxena"                 "Saurabh Nagpal"              
##   [49,] "Vivek Saxena"                 "Neha Bhanote"                
##   [50,] "Vivek Saxena"                 "Nidhi Kapila"                
##   [51,] "Vivek Saxena"                 "Akshay Bhardwaj"             
##   [52,] "Vivek Saxena"                 "Varun Gautam"                
##   [53,] "Vivek Saxena"                 "Kumar Prashant"              
##   [54,] "Vivek Saxena"                 "Jyoti Gupta"                 
##   [55,] "Vivek Saxena"                 "Gurwinderpal Singh"          
##   [56,] "Vivek Saxena"                 "Akhlak Khan"                 
##   [57,] "Vivek Saxena"                 "Ruchika Rajinder Gupta"      
##   [58,] "Vivek Saxena"                 "Tejbir Kaur"                 
##   [59,] "Vivek Saxena"                 "Isha Sikka Dhingra"          
##   [60,] "Vivek Saxena"                 "Meenu Hooda"                 
##   [61,] "Vivek Saxena"                 "Yash Sharma"                 
##   [62,] "Vivek Saxena"                 "Kanika Grover"               
##   [63,] "Vivek Saxena"                 "Shelly Dawar"                
##   [64,] "Vivek Saxena"                 "Khushboo Shankar Verma"      
##   [65,] "Vivek Saxena"                 "Shweta Sumit Kapoor"         
##   [66,] "Vivek Saxena"                 "Aamir Hakeem"                
##   [67,] "Vivek Saxena"                 "Dilpreet Singh"              
##   [68,] "Vivek Saxena"                 "Ashu Malik"                  
##   [69,] "Vivek Saxena"                 "Sahil Aggarwal"              
##   [70,] "Vivek Saxena"                 "Ashish Sharma"               
##   [71,] "Vivek Saxena"                 "Vidya Shankar Prasad"        
##   [72,] "Vivek Saxena"                 "Shivendra Mathur"            
##   [73,] "Vivek Saxena"                 "Tanvee Pathak"               
##   [74,] "Vivek Saxena"                 "Nitin Sharma"                
##   [75,] "Vivek Saxena"                 "Gagandeep Atwal"             
##   [76,] "Vivek Saxena"                 "Saadgi Kawal Preet"          
##   [77,] "Vivek Saxena"                 "Harivansh Kumar"             
##   [78,] "Vivek Saxena"                 "Shashi Kant Pandey"          
##   [79,] "Vivek Saxena"                 "Gurveer Kaur Sandhu"         
##   [80,] "Vivek Saxena"                 "Rocky Malhotra"              
##   [81,] "Vivek Saxena"                 "Gaurav Kassal"               
##   [82,] "Vivek Saxena"                 "Malika Thakral"              
##   [83,] "Vivek Saxena"                 "Amandeep Kaur"               
##   [84,] "Vivek Saxena"                 "Dimple Sharma"               
##   [85,] "Vivek Saxena"                 "Anju Arora"                  
##   [86,] "Vivek Saxena"                 "Neena Malhotra"              
##   [87,] "Vivek Saxena"                 "Ravinder Kumar"              
##   [88,] "Vivek Saxena"                 "Rabia Chhabra"               
##   [89,] "Vivek Saxena"                 "Shailesh Tiwari"             
##   [90,] "Vivek Saxena"                 "Nindy Kaur"                  
##   [91,] "Vivek Saxena"                 "Avinash Kaur Deol"           
##   [92,] "Vivek Saxena"                 "Pranav Ranjan"               
##   [93,] "Vivek Saxena"                 "Sandeep Vij"                 
##   [94,] "Vivek Saxena"                 "Manish Kumar"                
##   [95,] "Vivek Saxena"                 "Vikas Garg"                  
##   [96,] "Vivek Saxena"                 "Lalita Sharma"               
##   [97,] "Vivek Saxena"                 "Amar Cheema"                 
##   [98,] "Vivek Saxena"                 "Dawar Gaurav"                
##   [99,] "Vivek Saxena"                 "Nisha S Duvedi"              
##  [100,] "Vivek Saxena"                 "Anu Malhotra"                
##  [101,] "Vivek Saxena"                 "Mehak Malhotra"              
##  [102,] "Karan Sharma"                 "Jatin Khurana"               
##  [103,] "Karan Sharma"                 "Yogesh Sharma"               
##  [104,] "Karan Sharma"                 "Vishwajeet Singh"            
##  [105,] "Karan Sharma"                 "Vikas Anand"                 
##  [106,] "Karan Sharma"                 "Shelly Bhalla"               
##  [107,] "Karan Sharma"                 "Kumar Prashant"              
##  [108,] "Karan Sharma"                 "Saurabh Yadav"               
##  [109,] "Karan Sharma"                 "Kanika Grover"               
##  [110,] "Karan Sharma"                 "Divesh Arora"                
##  [111,] "Karan Sharma"                 "Rohit Singh"                 
##  [112,] "Karan Sharma"                 "Vibhu Babbar"                
##  [113,] "Karan Sharma"                 "Tanu Kunal Deo"              
##  [114,] "Karan Sharma"                 "Harivansh Kumar"             
##  [115,] "Karan Sharma"                 "Vinish Kumar"                
##  [116,] "Karan Sharma"                 "Deepak Sharma"               
##  [117,] "Karan Sharma"                 "Anshule Handoo"              
##  [118,] "Karan Sharma"                 "Abhay Singh"                 
##  [119,] "Karan Sharma"                 "Shailesh Tiwari"             
##  [120,] "Karan Sharma"                 "Pranav Ranjan"               
##  [121,] "Karan Sharma"                 "Niraj Awasthi"               
##  [122,] "Karan Sharma"                 "Rajandeep Kaur"              
##  [123,] "Karan Sharma"                 "Neha Bedi"                   
##  [124,] "Karan Sharma"                 "Gaurav Arora"                
##  [125,] "Karan Sharma"                 "Niraj Awasthi"               
##  [126,] "Anupriya Ambastha"            "Yogesh Sharma"               
##  [127,] "Anupriya Ambastha"            "Satya Prakash"               
##  [128,] "Anupriya Ambastha"            "Vishwajeet Singh"            
##  [129,] "Anupriya Ambastha"            "Gaurav Fidato"               
##  [130,] "Anupriya Ambastha"            "Sakshi Vidit Shrivastva"     
##  [131,] "Anupriya Ambastha"            "Rajnish Singh"               
##  [132,] "Anupriya Ambastha"            "Kanika Grover"               
##  [133,] "Anupriya Ambastha"            "Jasmeet Singh Meeti"         
##  [134,] "Anupriya Ambastha"            "Robin Singh Siwach"          
##  [135,] "Anupriya Ambastha"            "Vishal Cool"                 
##  [136,] "Anupriya Ambastha"            "Rohit Singh"                 
##  [137,] "Anupriya Ambastha"            "Gaurav Arora"                
##  [138,] "Anupriya Ambastha"            "Vibhu Babbar"                
##  [139,] "Anupriya Ambastha"            "Tanu Kunal Deo"              
##  [140,] "Anupriya Ambastha"            "Harivansh Kumar"             
##  [141,] "Anupriya Ambastha"            "Gaurav Kassal"               
##  [142,] "Anupriya Ambastha"            "Shailesh Tiwari"             
##  [143,] "Anupriya Ambastha"            "Pranav Ranjan"               
##  [144,] "Anupriya Ambastha"            "Harpreet Bedi"               
##  [145,] "Anupriya Ambastha"            "Neha Bedi"                   
##  [146,] "Anupriya Ambastha"            "Gaurav Arora"                
##  [147,] "Anupriya Ambastha"            "Vipul Garg"                  
##  [148,] "Ashish Dargan"                "Vimal Saini"                 
##  [149,] "Ashish Dargan"                "Disha Sz"                    
##  [150,] "Ashish Dargan"                "Shammi Dhiman"               
#### Truncated to 150 results ####     


> myFriendsNetwork2 = getNetwork(access_token, format = "adj.matrix", verbose = TRUE)

> myFriendsNetwork2

FB Data Mining// 
##                              Silky Prabhakar Ramphal Vivek Saxena
## Silky Prabhakar Ramphal                        FALSE         TRUE
## Vivek Saxena                                    TRUE        FALSE
## Karan Sharma                                   FALSE        FALSE
## Anupriya Ambastha                              FALSE        FALSE
## Ashish Dargan                                  FALSE        FALSE
## Kumar Saurabh                                  FALSE         TRUE
## Satyapal Singh                                 FALSE        FALSE
## Neha Shandilya                                 FALSE         TRUE
## Parminder Dhaliwal                             FALSE        FALSE
// 
##                       Karan Sharma Anupriya Ambastha Ashish Dargan
## Silky Prabhakar Ramphal    FALSE             FALSE         FALSE
## Vivek Saxena               FALSE             FALSE         FALSE
## Karan Sharma               FALSE             FALSE         FALSE
## Anupriya Ambastha          FALSE             FALSE         FALSE
## Utkarsh Shrivastava        FALSE             FALSE         FALSE

FB Data Mining// 
##                       Kumar Saurabh Satyapal Singh Neha Shandilya
## Silky Prabhakar Ramphal   FALSE          FALSE          FALSE
## Vivek Saxena               TRUE          FALSE           TRUE
## Karan Sharma              FALSE          FALSE          FALSE
## Anupriya Ambastha         FALSE          FALSE          FALSE
## Ashish Dargan             FALSE          FALSE          FALSE
## Kumar Saurabh             FALSE          FALSE           TRUE

####################################################

Using fbOAuth for longer login sessions:

# go to https://developers.facebook.com/apps and setup the app

fb_OAuth

fb_OAuth1

app_id = “xxxxxxxxxxxxxxxxxxxxxxxxxx”
app_secret = “xxxxxxxxxxxxxxxxxxxxx”
fb_auth<- fbOAuth(app_id = app_id, app_secret = app_secret, extended_permissions = TRUE)
save(fb_auth, file=”fb_oauth”)
load(“fb_oauth”)
me <- getUsers(“me”, token=fb_oauth, private_info = TRUE)

Currently it is giving an error:

Error in callAPI(query, token) :
(#12) username is deprecated for versions v2.0 and higher

And Rfacebook package is being updated to resolve this issue. I will notify, soon it is updated.

That’s all for now, folks!!

Will revert soon with some more…

Manoj

Advertisements