Knowing Which Facebook Users Are on Your Web Site
You now know how to access data about your users and you know what data is available. Now how do you identify those users? You can't pull identifying information about a Facebook user without having him or her log in first. However, you do have a few ways to get the user to log in so that you can access his or her data. Here are a few ideas:
- Include a Login button. When the user clicks this button, you can call FB.login and get the proper permissions that you need to access data about that user.
- Detect the user's status and automatically log him in if he's not logged in. This can happen two ways:
- • On your Web site: You can use FB.getLoginStatus() to determine whether the user is logged in and then prompt him if he is not, or if he doesn't have the appropriate permissions.
- • On a Canvas Page: FB.getLoginStatus() should work on Canvas Pages as well, but I have some issues with it. Instead, I parse the signature for the user and look for a user_id parameter. If it exists, I know that the user is logged in (I also know his Facebook ID). If it doesn't exist, I need to redirect him through the OAuth process to log in.
Parsing the signature is something that most language libraries should do automatically for you. For instance, in PHP, $facebook->getSession() should automatically parse the signed request for you and determine whether ...
Get Facebook® Application Development For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.