Skip to content

Instantly share code, notes, and snippets.

@nguyenphucbao68
Last active November 17, 2018 02:55
Show Gist options
  • Save nguyenphucbao68/f3e123cdd9d25cfd47dde78525dc5ad8 to your computer and use it in GitHub Desktop.
Save nguyenphucbao68/f3e123cdd9d25cfd47dde78525dc5ad8 to your computer and use it in GitHub Desktop.
Check Commented Function
/*
* Check Commented Function - jack098.blogspot.com
*/
var checkCmt = checkCommented(token, ID_USER, ID_PAGE, ID_POST);
checkCmt.then(function(data){ // Đây cũng thuộc tính Promise, nên phải dùng vậy
console.log((jQuery.isEmptyObject(data["data"])) ? false : true);
});
function checkCommented(access_token, uid, page_id, post_id) {
// Check Commented
var fields = ["id", "text", "time", "fromid", "is_private"]; // Số field cần lấy
var select = ""; // Tạo Select cho FQL
fields.forEach(function(value){
select += value + ',';
});
select = select.substring(0, select.length - 1); // loại bỏ dấu , phía cuối
// Lưu ý : 6 dòng trên là không bắt buộc, bạn có thể bỏ nó vào thẳng trong câu lênh bên dưới cũng dc
return fetch("//graph.facebook.com/fql?q=SELECT+"+select+"+FROM+comment+WHERE+post_id=%22"+page_id+"_"+post_id+"%22+and+fromid="+uid+"&access_token="+access_token).then(function(res){
try{
if (res.status == 400) throw "Bad Request"; // bắt lỗi - xem Api có chả về Http Code là 400 hay không?
if (res.status == 200)
return res.json() // nếu thành công thì chả về dạng JSON
else throw "Fail"; // không phải thì cụng False luôn
}catch(error){
console.log(error); // In ra lỗi
return false;
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment