Facebook helps you simplify and enhance user registration and sign-in by using Facebook as your login system. Users no longer need to fill in yet another registration form or remember another username and password to use your site. As long as the user is signed into Facebook, they are automatically signed into your site as well. Using Facebook for login provides you with all the information you need to create a social, personalized experience from the moment the user visits your site in their browser.
Facebook Platform uses OAuth 2.0 for authorization and authorization. While you can add login to your site using OAuth 2.0 directly (see our Login Overview), the open source JavaScript SDK is the simplest way to use Facebook for Login.
The JavaScript SDK requires that you register your website with Facebook to get an Application ID (or appId). The appId is a unique identifier for your site that ensures that we have the right level of security in place between the user and your website. The following example shows how to load the JavaScript SDK once you have your appId:
Once you have loaded the JavaScript SDK into your page and initialized it with your appId, you simply add the Login Button to your page using the <fb:login-button> XFBML element as shown below:
<fb:login-button>Login with Facebook</fb:login-button>
</body>
</html>
複製代碼
When the user loads the page in their browser, the JavaScript SDK renders the Login Button on your page:
In order to log the user into your site, three things need to happen. First, Facebook needs to authenticate the user. This ensures that the user is who they say they are. Second, Facebook needs to authenticate your website. This ensures that the user is giving their information to your site and not someone else. Lastly, the user must explicitly authorize your website to access their information. This ensures that the user knows exactly what data they are disclosing to your site.
These steps may seem complex, but fortunately all you need to do is use the fb:login-button and all the user needs to do is click it. When the user does so, the JavaScript SDK will ensure that the user is signed into Facebook and that the request is coming from your website. We then present an authorization dialog in their browser that provides information about your site and the user data you are requesting. By default, this dialog looks like the below:
If the user clicks Allow, we will give your site access to the requested information. If the user clicks, Don't Allow the dialog will close and no information will be available to your website. By default, we give you access to the user's name, picture and any other data they have shared with everyone on Facebook (see the User Graph object for more details).
If you need access to more information, such as the user's email address, etc. you must request permissi** for this information. If you can do this by adding the permissi** you need to the perms attribute of the fb:login-button like below:
When the user clicks the login button from this page, they will see the below authorization dialog. Note that there are now two new secti** that outline the additional information that your site is requesting permission to access.
A full list of permissi** is available in our permissi** guide. There is a strong inverse correlation between the number of permissi** your site requests and the number of users that will allow those permissi**. The greater the number of permissi** you ask for, the lower the number of users that will grant them; so we recommend that you only request the permissi** you absolutely need for your site.
In addition to Login Button, we offer the Registration Plugin. The Registration Plugin offers two key features not available with the Login Button: support for users without Facebook accounts and the ability to request additional user information that Facebook may not have or make available.
Using the Registration Plugin is just as simple as using the Login Button. You merely need to use the fb:registration XFBML element in your page, rather than the Login Button:
Facebook helps you simplify and enhance user registration and sign-in by using Facebook as your login system. Users no longer need to fill in yet another registration form or remember another username and password to use your site. As long as the user is signed into Facebook, they are automatically signed into your site as well. Using Facebook for login provides you with all the information you need to create a social, personalized experience from the moment the user visits your site in their browser.
Facebook Platform uses OAuth 2.0 for authorization and authorization. While you can add login to your site using OAuth 2.0 directly (see our Login Overview), the open source JavaScript SDK is the simplest way to use Facebook for Login.
The JavaScript SDK requires that you register your website with Facebook to get an Application ID (or appId). The appId is a unique identifier for your site that ensures that we have the right level of security in place between the user and your website. The following example shows how to load the JavaScript SDK once you have your appId:
Once you have loaded the JavaScript SDK into your page and initialized it with your appId, you simply add the Login Button to your page using the <fb:login-button> XFBML element as shown below:
<fb:login-button>Login with Facebook</fb:login-button>
</body>
</html>
複製代碼
When the user loads the page in their browser, the JavaScript SDK renders the Login Button on your page:
In order to log the user into your site, three things need to happen. First, Facebook needs to authenticate the user. This ensures that the user is who they say they are. Second, Facebook needs to authenticate your website. This ensures that the user is giving their information to your site and not someone else. Lastly, the user must explicitly authorize your website to access their information. This ensures that the user knows exactly what data they are disclosing to your site.
These steps may seem complex, but fortunately all you need to do is use the fb:login-button and all the user needs to do is click it. When the user does so, the JavaScript SDK will ensure that the user is signed into Facebook and that the request is coming from your website. We then present an authorization dialog in their browser that provides information about your site and the user data you are requesting. By default, this dialog looks like the below:
If the user clicks Allow, we will give your site access to the requested information. If the user clicks, Don't Allow the dialog will close and no information will be available to your website. By default, we give you access to the user's name, picture and any other data they have shared with everyone on Facebook (see the User Graph object for more details).
If you need access to more information, such as the user's email address, etc. you must request permissi** for this information. If you can do this by adding the permissi** you need to the perms attribute of the fb:login-button like below:
When the user clicks the login button from this page, they will see the below authorization dialog. Note that there are now two new secti** that outline the additional information that your site is requesting permission to access.
A full list of permissi** is available in our permissi** guide. There is a strong inverse correlation between the number of permissi** your site requests and the number of users that will allow those permissi**. The greater the number of permissi** you ask for, the lower the number of users that will grant them; so we recommend that you only request the permissi** you absolutely need for your site.
In addition to Login Button, we offer the Registration Plugin. The Registration Plugin offers two key features not available with the Login Button: support for users without Facebook accounts and the ability to request additional user information that Facebook may not have or make available.
Using the Registration Plugin is just as simple as using the Login Button. You merely need to use the fb:registration XFBML element in your page, rather than the Login Button:
If the user is not already logged into Facebook, they will see the below form. Notice that the form is not prefilled with any user information, but there is a link to login to Facebook to do so.
If the user is already logged into Facebook or decides to login from the registration form, they will see the below. Notice that the form is now prefilled with their Facebook information.
Once the user reviews the information and/or enters any custom fields (in the above example, favorite_car is a custom field that the user must populate directly, as it is not data that is currently part of the user's Facebook profile), the user clicks Register. This will start the authentication and authorization process which is denoted by the below dialog:
With authentication/authorization complete, we redirect the user to whatever URL you placed into the redirect-uri attribute of the fb:registration element which completes the registration process.
The Login Button and the Registration Plugin allow you to easily bring the more than 500 million Facebook users to your site. In doing so, you can also eliminate or reduce whole parts of your codebase. You can learn more about how to add Login with Facebook to your site by reading the documentation for the Login Button, the Registration Plugin and the JavaScript SDK.作者: hivenus 時間: 2011-1-13 17:38