Skip to content

Instantly share code, notes, and snippets.

@minhphuc429
Forked from nguyenphucbao68/CheckLikedFunction.js
Created November 17, 2018 02:55
Show Gist options
  • Save minhphuc429/d2b7e4ca8c8c88054e1919e06b1a03a6 to your computer and use it in GitHub Desktop.
Save minhphuc429/d2b7e4ca8c8c88054e1919e06b1a03a6 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