I'm trying to figure out a way to check if a user is logged in to Facebook before I render the Customer Chat Plugin.
It doesn't matter to me to know who is the user etc., just whether he is logged in at all.
I tried to explore most of the FB object properties but didn't come up with anything.
I tried later to use FB.init and FB.getLoginStatus but the widget disappears when I use it (and I'm not sure it will give me the result I'm asking for)
That´s possible with FB.getLoginStatus, you will get the status "not_authorized" if he is logged in on Facebook. I assume you want to load the plugin dynamically, so you have to use this after checking the status: https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/
Related
I'm using Facebook::Graph and any time a page is loaded, I would like to detect server-side if a user has liked a certain page or not. I can't find in the documentation how to do this though. Is it possible to do this without sending the user ID to my server-side script? Because I know using the javascript SDK you can check this, but I feel like it might be different with a server-side API.
Not sure what you mean with "anytime a page is loaded"... I guess you mean an page of an App? If so, you need the user_likes permission to be able to get the information on the User's likes.
If you're using a Page Tab App, then you could get this info out of the signed_request which is passed to the App once the User accesses it from the Facebook Page Tab. See https://developers.facebook.com/docs/reference/login/signed-request/ The indicator is in the page.liked field.
I have a webpage with a Facebook Like button (social plugin).
I need to show extra information on my page when the user has liked the page.
I know there has been similar questions but the answer has been to use the edge.create event to react to the user clicking the like button. This works fine except when the like happened prior to loading the page.
Others have suggested using a signed_request but I believe this is only applicable to canvas applications,
I know I can use the API to check for the like but this requires the user to grant permissions, but I want to do this in an anonymous manner (I am not interested in knowing who the user is, I just want to know if they liked the page).
Is there any way to do it?
Well this is exactly the difference between having a canvas app and a site that just uses the plugins. The plugin allows (you to allow) the user to like a certain URL and that's about all. In order for the site operating outside of Facebook at explicitly access that data, it'll need the correct permissions as you have noted... the user_likes permission.
Without a signed_request or the relevant permissions from the user, I do not believe that you'll be able to differentiate between users that have "liked" your URL.
Use a javascript onclick to detect when the like button is clicked and localStorage to store the info?
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.
thanks!
Just want to update that this is not possible (as answered below) with the current FB api.
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.
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.
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.
Similar to the ever-trendy Fan Page trick that allows page owners to only show certain content when a user performs the 'like' action (visible-to-connection), I wish to be able to only show certain content on a website once a user has liked the website.
If there is no FB code for this, I have considered using a Facebook like callback (triggered when a user likes on the current page) to set a cookie that establishes a user has liked the page or perhaps a database table that sets a users status to 'liked', again using the callback within the documentation.
Any ideas would be helpful. Thanks.
I haven't seen a "fangate" implementation for non-Facebook pages that didn't require you to go through the full Facebook authentication process (with the user_likes scope) first. You could set a cookie when they like, but that'll only work if they liked it via your site (i.e. if they liked you on Facebook, it wouldn't get caught by your site), and the cookie could get deleted or lost.
you can use the Javascipt SDK to easily accomplish this.
First, call FB.init:
https://developers.facebook.com/docs/reference/javascript/FB.init/
Then call getLoginStatus:
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
If they're not logged in ( not authorized your app ), then call
FB.login and then recall getLoginStatus.
If logged in, then get the user's likes via FQL:
https://developers.facebook.com/docs/reference/javascript/FB.Data.query/
I'm implementing a simple Facebook "Like" button on a voting site but want an option which votes using the internal "Like" system for anyone who doesn't have a Facebook account/doesn't want to log in (this may seem like an odd request but this is a requirement for the client).
So basically I'd like a way of detecting if someone is logged in without having to use the graph API - just using Open Graph Protocol. Is there any way of doing this?
If you subscribe to auth.statusChange event, it might do the trick, as noted on this page:
Typically you will want to use the auth.sessionChange event. But in rare cases, you want to distinguish between these three states:
Connected
Logged into Facebook but not connected with your application
Not logged into Facebook at all.
The FB.Event.subscribe and FB.Event.unsubscribe functions are used to subscribe to these events.
Returned status would contain either connected, notConnected (logged in to facebook but not to your app) or unknown.
I am not sure if this would work as planned though as I haven't tried it myself. It might return notConnected status only for users that authorized your app in the past, but it seems like a step in the right direction.