Skip to content

Instantly share code, notes, and snippets.

@nguyenphucbao68
Created July 25, 2017 11:22
Show Gist options
  • Save nguyenphucbao68/6f6705e3a134de950753997e60f1943c to your computer and use it in GitHub Desktop.
Save nguyenphucbao68/6f6705e3a134de950753997e60f1943c to your computer and use it in GitHub Desktop.
/*
* Check Liked Function - jack098.blogspot.com
*/
var checkLike = checkLiked(token, ID_USER, ID_PAGE, ID_POST);
checkLike.then(function(data){
console.log((jQuery.isEmptyObject(data["data"])) ? false : true);
})
function checkLiked(access_token, uid, page_id, post_id) {
// Check Liked
return fetch("//graph.facebook.com/fql?q=SELECT+user_id+FROM+like+WHERE+post_id=%22"+page_id+"_"+post_id+"%22+and+user_id="+uid+"&access_token="+access_token).then(function(res){
console.log(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