-1
I was impressed not to find this question in similar questions. The fact, however, is that I have already found this question several times in English on this site, and none of the solutions presented solved my problem. Maybe because these questions I found in English are old, and facebook lives updating ways to use facebook javascript SDK. I want to know how today I do to know whether or not a certain user likes my facebook page JS SDK. I’m tired of looking for the solution on the internet and nothing works. My code for it doesn’t work. Here’s the code:
$(document).ready( function () {
try {
FB.init({
appId : '{meu_ap_id}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
version: 'v5.0'
});
} catch (e) {
alert(e.message);
}
FB.getLoginStatus(function(response) {
if (response['status'] == 'connected') {
token = response['authResponse']['accessToken'];
FB.api('/me/likes/{page-id}', 'get', {access_token: token} function(result) {
alert(result);
if (result){
alert('is fan');
} else alert ('not a fan');
}); */
}
});
});
The init() works. getLoginStatus() also works by returning 'Connected' (this after I have saved in my application’s configuration the url of my site as a valid redirection url to Oauth2. But FB.api(), as exposed in the code does not work. Can anyone tell what is wrong in my FB.api(), or also in another part of the code? For example: the Alert(result) I put inside the callback function to test the code does not run, implying that everything within FB.api does not run. From now on, thank you.
I want to say that I’ve already found two syntax errors in this code. Well. now the code only returns "is fan", even though I haven’t liked the page.
– Tulio Rubim
better read the documentation of the Facebook api, there it is updated and even in Portuguese: https://developers.facebook.com/docs/graph-api/reference/v6.0/object/likes
– Ricardo Pontual