Forked from nguyenphucbao68/CheckCommentedFunction.js
Created
November 17, 2018 02:55
-
-
Save minhphuc429/1d63d89ae19658aad0949b9e3ede858a to your computer and use it in GitHub Desktop.
Check Commented Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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