Fblikes predictor_Priya Ganadas

This is my attempt to make a pun at people who are obsessed with approvals, fb likes being a measurable factor in social media. If you had a fblikes predictor, would you improve your chances of getting liked by people?

For my data scraping assignment, I want to use my facebook account. I plan to scrape data of fb likes by my friends.
The Process-
1. List all the status messages posted.
2. List all the people who liked particular status message.
3. Assign labels to the status message(tagging in terms of keywords).
4. Draw a graph of keywords vs Fb likes.

This graph would show possibility of getting a like by people if certain keywords are used or if the status expresses emotions of certain kind.

Further: I would like to track 50 of my friends to visualise their pattern of liking my status message.

Depending on this data, the graph would also extrapolate or predict. If a future status message is typed in, ideally, I should know % chance of likelihood that who of those 50 friends would end up hitting ‘like’ to my status message.

 

Code-
This code is built off Ben Grosser’s examples for temboo.

import com.temboo.core.*;
import com.temboo.Library.Facebook.Reading.*;
 
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("ypag","myFirstApp","");
 
String accessToken = ""; // INSERT YOUR FACEBOOK TOKEN HERE
 
ArrayList friendNames;
ArrayList friendIDs;
 
void setup() {
 
  // grab (and print) your friend data from FB. fills 2 ArrayLists:
  // friendNames 
  // friendIDs
  getFriendIDs();
 
  // get your own statuses and names of who liked them
  getStatuses("me");
 
  // WARNING WARNING WARNING
  // This will grab data for EVERY friend! This can be a lot of data
  // you can just call getStatuses("00010202309202") for whichever friend you 
  // want data from instead of getting data from all of them
   
//  run through all of your friends and get their statuses and who liked them
//  for(int i = 0; i < friendIDs.size(); i++) {
//    String friendID = friendIDs.get(i).toString();
//    String friendName = friendNames.get(i).toString();
//    println("\n---------------------------------------------");
//    println("STATUSES FOR: "+friendName);
//    getStatuses(friendID);
//  }
   
}
 
// gets all your friends and returns an array with their IDs
void getFriendIDs() {
  Friends friendsConnector = new Friends(session);
  friendsConnector.setAccessToken(accessToken);
  FriendsResultSet friendsResults = friendsConnector.run();
  //println(friendsResults.getResponse());
  JSONObject response = parseJSONObject(friendsResults.getResponse());
  JSONArray data = response.getJSONArray("data");
   
  friendIDs = new ArrayList();
  friendNames = new ArrayList();
   
  for(int i = 0; i < data.size(); i++) {
    JSONObject friend = data.getJSONObject(i);
    String name = friend.getString("name");
    String id = friend.getString("id");
     
    friendIDs.add(id);
    friendNames.add(name);
     
    //println(name + " : " + id);
  }
}
 
void getStatuses(String profileID) {
  // Create the Choreo object using your Temboo session
  Statuses statusesChoreo = new Statuses(session);
 
  // Set inputs
  statusesChoreo.setAccessToken(accessToken);
   
  if(profileID != "me") {
    statusesChoreo.setProfileID(profileID);
  }
   
  // Run the Choreo and store the results
  StatusesResultSet statusesResults = statusesChoreo.run();
 
  // want to see what you're getting? print out statusesResults.getResponse(), 
  // copy output, and then paste into a JSON beautifer, like http://jsonformatter.curiousconcept.com/
  // println(statusesResults.getResponse());
   
  // extract and printout status info  
  printStatusInfo(statusesResults);
 
}
 
// looks at a statusResult and extracts some info
// needs to be customized to meet your needs if they're different than this 
// https://temboo.com/processing/parsing-json can be helpful trying to figure it out
void printStatusInfo(StatusesResultSet s) {
   
  // create a JSONObject from the StatusesResultSet
  JSONObject response = parseJSONObject(s.getResponse());  
 
  // 'data' holds all of our response data  
  JSONArray data = response.getJSONArray("data");
   
  // print raw data
  //println(data);
     
  // run through the objects in data (our statuses)
  for(int i = 0; i < 10; i++) {
     
    // extract a status from the data
    JSONObject status = data.getJSONObject(i);
     
    // see if there's a message (sometimes there's not)
    // extract the message string if there is one
    String message;
        
    try {
      message = status.getString("message");
    } catch (Exception e) {
      message = null;
    }
     
    // if we don't have one, skip to the next for() iteration
    if(message == null) continue;
     
    // print the message string (e.g. the status)
    println("\n\n"+message);
     
    // check for and get all the likers of this status
    // if there are any
    JSONObject likes;
     
    // see if there are any likes (there may not be)
    // use try/catch as if there aren't any it throws 
    // an error --- this lets us get by it if there is
    try {
      likes = status.getJSONObject("likes");
    } catch (Exception e) {
      likes = null;
    }
 
    // if there are some likes, process them
    if(likes != null) {
       
      // get an array of all the likers
      JSONArray likers = likes.getJSONArray("data");
       
      // we have some, so printout a header
      println("  Liked by:");
       
      // run through all of the likes, extract/print name
      for(int j = 0; j < likers.size(); j++) {
        String liker = likers.getJSONObject(j).getString("name");
        println("   -"+liker);
        if(liker.equals("Raj Lakshmee"))
            { println (" wohoo!!" );
            }
      }
       
    } // end like process
     
  } // end of status for()
   
}

Visualisation- Would consist of keywords in fb status where the size of region is proportional to the number of likes.

datascrape