Wednesday, June 12, 2013

Bikin Notif Pengunjung ala Facebook diBlog (versi Google Script)

Udah gak usah dijelasin lagi kali kayanya ya, noh tuh kan contonya (kalo masih) ada dipojok kiri bawah.

Dulu di Blog yang lama juga udah pernah dishare scriptnya kalo gak salah, tapi emang yang itu DataBase untuk penyimpanan data pengunjung-nya masih pake Feed dari Facebook Page, nah kalo yang sekarang udah dipindah pake ScriptDB-nya Google Script.

Sebenernya kalo dibilang beda juga gak jauh-jauh amat kayanya, antara nyimpen sama ngambil datanya juga tetep pake API, cuman emang kalo ScriptDB-nya Google Script gak butuh Access_token, tapi kalo soal privacy data sih tetep aja public open; semua orang bisa access read/write.

Ada beberapa yang masih jadi ganjelan dari Blog Notif yang sekarang ini:
  • Apakah ada/Berapa limit penyimpanan dari ScriptDB ini.
  • Masih suka kepentok masalah Limit Eksekusi Script, jadi kalo pengunjung blognya rame, butuh lebih dari satu ScriptDB.
  • Belum ketemu gimana caranya biar write access ke-ScriptDB hanya bisa dari satu subdomain saja.
Karena disini bukan forum copy-paste, jadi mending kita bahas ditelnya dulu okeh?
udah, okeh aja,, daripada gak dibagi :P

ScriptDb

ScriptDb is a JavaScript Object database for Google Apps Script.

Saving Data

function saveToDB(){
  var db=ScriptDb.getMyDb();
  var whatToSave={
    visitor:{
      id:"4",
      name:"Zuck",
      page_title:"AingCreations",
      page_uri:"http://aingcreations-reborn.blogspot.com/",
      action:"viewed",
      browser:"Firefox 10",
      time:"2013-05-20T17:11:45+0000"
    }
  };
  db.save(whatToSave);
}

Collecting Data

function collectDB(){
  var visitors=[];
  var count=0;
  var limiting=5;

  var db=ScriptDb.getMyDb();
  var whatToCollect={visitor:db.anyValue()};
  var searchOnDB=db.query(whatToCollect);
  while(searchOnDB.hasNext()){
    var fromDB=searchOnDB.next();
    visitors.push(fromDB.visitor);
    count++;
    if(count==limiting){break}
  }

  var Lol="\nFound: "+visitors.length+" Visitors\n"+JSON.stringify(visitors,null,"  ");
  Logger.log(Lol);
}

Modifying Data

function modifDB(){
  var db=ScriptDb.getMyDb();
  var whatToModify={visitor:{id:"4"}};
  var modifPart={
    partName:"time",
    partVal:"2013-06-10T00:00:00+0000"
  }
  var searchOnDB=db.query(whatToModify);
  while(searchOnDB.hasNext()){
    var whatToSave=searchOnDB.next();
    whatToSave.visitor[modifPart.partName]=modifPart.partVal;
    db.save(whatToSave);
  }
}

Deleting Data

function dellDB(){
  var db=ScriptDb.getMyDb();
  var whatToDell={visitor:{id:"4"}};
  var searchOnDB=db.query(whatToDell);
  while(searchOnDB.hasNext()){
    db.remove(searchOnDB.next());
  }
}

ContentService

When a script is published as a web app, the special callback functions doGet() and doPost() are invoked whenever a request is made to the script's URL. The ContentService can be used to return raw textual content. This allows you to write scripts that act as services, responding to GET and POST requests and serving data of various mime-types.

Codes at Google Script

Publishing as a Web App

Testing

Getting visitor facebook ID

The important thing about this Blog Notif is visitor facebook ID. We can get this ID by connecting our blog to facebook or better known as Facebook Connect.

I'm not writing yet about this, but you may still learn it from http://developers.facebook.com/ or you may analyze this blog source script if you want :)

By knowing our visitor facebook ID, then we can fetch more information about our visitor from facebook, such as their profile photo, locale language, gender etc.

Tester HTML File

To learn more about how the script flows, Download this BlogNotifTester.htm file, open/drag and drop into browser new tab, use browser console to monitor the script flow.

~ Have a good day :)

Sunday, June 2, 2013

Feed Cleaner ( this is how your posts or comments are deleted in our group :P )

Detect if User Posting More Then 1 Post in an Hour, Detect Post with Private Link or Attachment Not Available, Detect Comment Message Less Then 10 Characters, Detect Comment Message More Than 1000 Characters, Detect Comment Message with Repetition Characters More Then 10 Characters, Detect Comment Message with Repetition Words More Than 10 Words
App ID/API Key: Get Token
Wall ID:
Access Token:
Forbidden User IDs on Comment (split by comas):
Forbidden User IDs on Post (split by comas):
List of Forbidden Words in Regular Expression:
Load it Now