Time Capsule Post : Physically Manifesting Facebook Comments

At first, I managed to use the Temboo Facebook choreo to post a test message:

fbtest

Temboo provides much more Facebook functionality than that, so I wove together a couple more choreos to create the Time Capsule Post. This would consist of an Arduino which, when a button is pushed, would automatically post a status on Facebook. After 12 hours, this status would be automatically deleted, but not before all comments made on the post were downloaded onto the Arduino. As a result, the comments would no longer exist anywhere other than within the memory of the Arduino chip (and probably backed up deep in some Facebook server). Here was my attempted post :

fbtest2

Even though it was posted to my timeline and set to be visible to everyone, no account other than my own was able to view the post. I therefore posted some filler comments myself, and ran the autodelete/comment parsing code, returning this result:

fbtest3

While I never actually constructed the simple pushbutton circuit necessary to run the code, I did create an Arduino C program which would both send and receive data serially to/from my Processing sketch:

Processing:

import com.temboo.core.*;
import com.temboo.Library.Facebook.Deleting.*;
import com.temboo.Library.Facebook.Reading.*;
import com.temboo.Library.Facebook.Publishing.*;
import processing.serial.*;
Serial myPort;
String statid;
String[] results;
int startTime;
boolean posted = false;
int ValueIn;
int ValueOut;

TembooSession session = new TembooSession("hex", "facebooklikekeepingupwith", "4v2AjLyKERbZ8Ate9uuDXYGLINaujfjr");
void setup() {
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void collectInput()
{
  while(myPort.available () > 0 && posted == false)
  {
    char aChar = (char) myPort.read();
    if (aChar == 'o')
    {
      posted = true
      statid = runPostChoreo();
      startTime = hour();
    }
  }
}

void draw()
{
  collectInput();
  if (posted && (hour() == (startTime + 12) % 24 || keyPressed))
  {
    results = runCommentsChoreo();
    myPort.write(results);
    println(results);
    runDeleteStatusChoreo();
  }
}

String[] runCommentsChoreo() {
  Comments commentsChoreo = new Comments(session);

  commentsChoreo.setCredential("FacebookAccount");

  commentsChoreo.setObjectID(statid);

  CommentsResultSet commentsResults = commentsChoreo.run();
  
  println(commentsResults.getResponse());
  println(commentsResults.getHasNext());
  println(commentsResults.getHasPrevious());
  return parseComments(commentsResults.getResponse());
}

String runPostChoreo() {
  Post postChoreo = new Post(session);

  postChoreo.setCredential("FacebookAccount");

  postChoreo.setMessage("This is a Time Capsule Post. In 12 hours, this post will be deleted automatically. Any comments on this post will be archived in a digital capsule. This digital capsule will be buried on the Carnegie Mellon campus for the next 50 years, as a part of CMU's ongoing Social Archiving Initiative (SAI). Please comment, and your messages will be stashed away for posterity.");
  PostResultSet postResults = postChoreo.run();
  
  println(postResults.getResponse());
  return parseResults(postResults.getResponse());
}

void runDeleteStatusChoreo() {
  DeleteObject deleteObjectChoreo = new DeleteObject(session);

  deleteObjectChoreo.setCredential("FacebookAccount");

  deleteObjectChoreo.setObjectID(statid);

  DeleteObjectResultSet deleteObjectResults = deleteObjectChoreo.run();

  println(deleteObjectResults.getResponse());


}

String parseResults(String results)
{
  String digits = "0123456789_";
  while(results.indexOf("\"id\":\"") != -1)
  {
    results = results.substring(results.indexOf("\"id\":\"") + 6);
    for(int i = 0; i < results.length(); i++)
    {
      if (digits.indexOf(results.charAt(i)) == -1)
      {
        return results.substring(0,i);
      }
    }
  }
  return "-1";
}

String[] parseComments(String results)
{
  String[] comments = new String[results.split("from").length-1];
  if (comments.length == 0)
  {
    return new String[] {"no comments"};
  }
  String commenter = "", comment = "";
  int index = 0;
  while(results.indexOf("\"from\":") != -1)
  {
    results = results.substring(results.indexOf("\"from\":\"") + 8);
    results = results.substring(results.indexOf("\"name\":\"") + 8);
    for(int i = 0; i < results.length(); i++)
    {
      if (results.charAt(i) == '\"')
      {
        commenter = results.substring(0,i);
        println("commenter: " + commenter);
        break;
      }
    }
    results = results.substring(results.indexOf("\"message\":\"") + 11);
    for(int i = 0; i < results.length(); i++)
    {
      if (results.charAt(i) == '"')
      {
        comment = results.substring(0,i);
        println("comment: " + comment);
        break;
      }
    }
    comments[index] = commenter + ": " + comment;
    index++;
  }
  return comments;
}

Arduino C:

const int button = 2;
String inputString = "";         
boolean stringComplete = false;  
void setup()
{
  Serial.begin(9600);
  pinMode(button, INPUT);
}

void loop()
{
  int sensorReading = digitalRead(button);
  if(sensorReading == HIGH)
  {
    Serial.println("go");
  }
}

void serialEvent() 
{
  while (Serial.available())
  {
    char inChar = (char)Serial.read();
    inputString += inChar;
  }
}

Comments are closed.