Question

Using this method, facebook will return an object of the user's liked pages

FB.api('/me', {fields: 'gender, first_name, last_name, email, likes'}, function(response) {
    console.log(response);
}

result

email: "ariel@dropbox.com"
first_name: "Ariel"
gender: "female"
id: "178006027123671"
last_name: "Yeung"
likes: Object data: Array[2]

However, I only want to get the object whether this user is liking my facebook page

Était-ce utile?

La solution

As https://developers.facebook.com/docs/graph-api/reference/user/likes describes, you can ask whether the user likes a certain page using

/me/likes/{page_id}

Since you are asking for specific user fields already, you probably don’t want to make a separate API call for that – but you can fit it in there as well, using field expansion:

/me?fields=gender,first_name,last_name,email,likes.target_id({page_id})

If the user likes that particular page, you get a likes property in the response data.

(Not sure if that works using the syntax you are using currently as well, passing the fields via object, but you can simply try: {fields: 'gender, …, likes.target_id({page_id})'} … let us know if that works, thanks.)


Edit: Although this will still work, as long as you get user_likes permission from the user, Facebook will not approve the use of that permission for this singular purpose. Like Gating in any way, shape or form is not allowed any more.

Autres conseils

You canot get the list of users liking you page via graph api. So, you can not check wether or not a user has like your page directly.

You already have the likes of a user, just loop through them and check that your page is liked or not.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top