Reputation: 663
I would like to (in a non-intrusive way) to ask a visitor of our blog to like our facebook page. The problem is I don't want to show this message to everyone, just non-fans.
I've read through this post
How to check if a user likes my Facebook Page or URL using Facebook's API
and it appears that if you want to know if the user likes your facebook page, you need their permission.
My code is currently:
FB.api('/me/likes/--mypageid--',{limit: 1}, function(response) {
if( response.data ) {
if( !isEmpty(response.data) )
console.log('You are a fan!');
else
console.log('Not a fan!');
} else {
console.log(response);
}
});
Which always return an error: "An active access token must be used to query information about the current user."
I assume this is because I am not passing an access token, but to get this access token i have to ask the user for it, and I don't want any popups on my site.
Does anyone have any ideas how to accomplish this, I'm also open to any other suggestions on how to prompt users to like a page non-intrusively.
Just want to update that this is not possible (as answered below) with the current FB api.
Upvotes: 4
Views: 2596
Reputation: 7361
You could give a user a log in to the site. For example 'log in for live updates' or such like.
Create some kind of incentive for a user to set up a FB Login on your page, then in the login process you request 'User_likes' permission. With this you can simply reverse your logic and show the 'like us on FB' prompt to everyone except those who already have?
It's the only workaround I can think of, not ideal of course, but by opening up your blog as an open graph app like this it'll give you access to a whole load of social tools to help increase popularity of your blog via your most active/interested users.
Upvotes: 1
Reputation: 96407
I assume this is because I am not passing an access token,
Correct.
The API can’t know who /me
is supposed to be without an access token.
And furthermore, you would need to get the user’s permission to read his likes this way first.
but to get this access token i have to ask the user for it, and I don't want any popups on my site.
Outside Facebook, you have no right to know what an anonymous user liked or did not like.
You have to have the user connect to your app (and ask permission), before you can get that kind of info.
Of course this would be way over the top, to have a user connect and give permission just for that little effect you want to have. So stick with the like box, it’s all you can get with reasonable effort and without harassing users.
Upvotes: 1
Reputation: 11852
Why not just throw a Like Box somewhere on your page. It's unobtrusive and since Facebook never tells your page anything about the user, you don't have to authenticate them.
Otherwise, you will need to authenticate the user before Facebook will give you data about them.
Upvotes: 0