Monday, February 21, 2011

Facebook for Websites


Facebook Platform enables you to make your website more social. You can use our Social Plugins, such as the Like Button to drive user engagement with a single line of HTML. Our Login Button and Registration Plugin let you simplify or eliminate your own user registration and sign-in. Lastly, the Graph API lets you access the full social graph of a given user, allowing you to create a truly deep personal experience.
This guide will walk you through the basics of creating a web app that leverages these features. The examples in this guide use PHP for server-side programming and HTML/JavaScript for client-side code. These examples are very straightforward and easily translatable to other languages.
In this document:


Social Plugins

Social Plugins are the easiest way to get started with Facebook Platform. The plugins are embeddable social features that can be integrated in your site with a line of HTML. Because they are hosted by Facebook, the plugins are personalized for all users who are currently logged into Facebook, even if they are visiting your site for the first time.
The most important Social Plugin is the Like Button, which enables users to share your page with their friends with one click. You can add a Like button to any page with an iframe tag:

    
      My Great Web page
    
    
       
Once you have included the Like Button into your site, you can use other Social Plugins to turn those user interactions into more engaging experiences throughout your site. You can use the Activity Feed Plugin to show users a stream of the recent likes and comments from their friends on your site. You can use the Recommendations Plugin to show personalized page recommendations to your users based on the likes and comments across your entire site. Here are the activity and recommendations plugins for the Facebook Developers site:

Most Social Plugins can be integrated with your site by simply including the iframe tag for the plugin within your page. There are several Social Plugins, such as Comments and Live Stream, that require the use of XFBML (eXtended Facebook Markup Language). XFBML is a set of XML elements that can be included in your HTML pages to display Social Plugins. When your page is loaded, any XFBML elements found in the document are processed by the JavaScript SDK, resulting in the appropriate plugin being rendered on your page.
We provide XFBML elements for all of our Social Plugins. For example, the Like Button can also be placed on your page by using the XFBML equivalent:

 
    
      My Great Web page
    
    
      
      
    
 
The iframe versions of our plugins are the most widely, used as they require a minimal understanding of Facebook Platform. The XFBML versions are typically used by more sophisticated developers looking for more control and consistency in their codebase.
Getting started could not be simpler. Just select the plugin from our Social Plugin page and follow the steps in the provided configurator. These configurators, like the below, help you setup your plugin and generate all the code you need to add it to your site.
Like Config


Authentication

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 Authentication 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 App 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:
 
    
      My Facebook Login Page
    
    
      
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 XFBML element as shown below:
 
    
      My Facebook Login Page
    
    
      
Login with Facebook
When the user loads the page in their browser, the JavaScript SDK renders the Login Button on your page:
Login Button
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:
Authorization Dialog
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 permissions for this information. If you can do this by adding the permissions you need to the perms attribute of the fb:login-button like below:
 
    
      My Facebook Login Page
    
    
      
Login with Facebook
When the user clicks the login button from this page, they will see the below authorization dialog. Note that there are now two new sections that outline the additional information that your site is requesting permission to access.
Authorization Permissions
A full list of permissions is available in our permissions reference. There is a strong inverse correlation between the number of permissions your site requests and the number of users that will allow those permissions. The greater the number of permissions you ask for, the lower the number of users that will grant them; so we recommend that you only request the permissions 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:
 
    
      My Facebook Registration Page
    
    
      
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.
Registration No Login
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.
Registration Login
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:
Registration Sign in
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.


Personalization

While Social Plugins offer a easy way to personalized your site, once you have added login to your site, you can access the full power of the Graph API to create an even deeper personalized experience for your users. You can use the Graph API to access the user's Facebook profile, using this data in your own custom experience. You can use the Graph API to publish to the user's Facebook Wall and their News Feed. You can use the Graph API to access the user's social graph, bring their friends directly to your site all in your own custom experience.
The Javascript SDK provides a straightforward to access the Graph API: FB.api. This function takes a string argument which specifies the part of the Graph to target and a callback function that is invoked when the call completes. The following demonstrates how to use FB.api() to retrieve the user's picture and name from the Graph API and display it on a page within your site:

    
      My Great Website
    
    
      
Another way to personalize your site with the JavaScript SDK is the FB.ui function. This function invokes our Platform Dialogs within the context of your site. You can use the FB.ui function to post to the user's Feed or allow them to invite new friends. The following demonstrates how to use the Feed Dialog from your site:

    
      My Great Website
    
    
      
When this page is loaded in the user's browser, the JavaScript SDK will render the below dialog that the user can use to post to their feed. You can set a number of defaults for the dialog, which the user can then modify or override prior to posting.
Web Dialog
One of the best ways to learn what is possible with the JavaScript SDK is our JavaScript Console. The tool offers a host of examples that you can execute directly in the console itself before you make any changes to your site.
The Javascript SDK lets you access the Graph API and Platform Dialogs from client-side code but some of the most interesting integrations involve accessing the Graph API from server-side code running on your web server. The JavaScript SDK saves the details for the logged in user in a cookie named fbs_YOUR_APP_ID. The following PHP example shows you how to use access this cookie and then customize the generated page based on this information:
 $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $app_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']));

?>

  
    
      Welcome name ?>
    
      
    
    
Using the JavaScript SDK cookie is only one of several ways to access user credentials and information from server-side code. Our Security Guide highlights how to perform authentication and authorization directly from your web server allowing you to access the Graph API without using any client-side code.


Analytics

You can get detailed analytics about the demographics of your users and how users are sharing from your website with Insights.
Insights
Insights provides reports broken down by domain and by app. These reports include rich data about users sharing content from your site within Facebook and other Facebook-enabled apps no matter where those activity originated. For example, if a user puts a URL from your site into a Facebook status message, that data is included in the analytics for your domain.
The data from Insights is also available in the Graph API so you can integrate the Facebook analytics data with your own, in-house analytics systems.


Next Steps

This was a quick survey of the major features available to your website from Facebook Platform. Our core concepts documents provide deeper insight into the various pieces of Facebook Platform. The Graph API is a great place to start. If you are looking for a real world examples to help you get started building please see our Samples. If you are looking for inspiration, check out our Showcase.

MySQL Field Types with Size


MySQL supports a number of column types, which may be grouped into three categories: numeric types, date and time types, and string (character) types. This section first gives an overview of the types available. Please refer to the MySQL manuals for more details.

TypeUse forSize
TINYINTA very small integerThe signed range is 128 to 127. The unsigned range is 0 to 255.
SMALLINTA small integerThe signed range is 32768 to 32767. The unsigned range is 0 to 65535
MEDIUMINTA medium-size integerThe signed range is 8388608 to 8388607. The unsigned range is 0 to 16777215
INT or INTEGERA normal-size integerThe signed range is 2147483648 to 2147483647. The unsigned range is 0 to 4294967295
BIGINTA large integerThe signed range is 9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615
FLOATA small (single-precision) floating-point number. Cannot be unsignedRanges are 3.402823466E+38 to 1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38. If the number of Decimals is not set or <= 24 it is a single-precision floating point number
DOUBLE,
DOUBLE PRECISION,
REAL
A normal-size (double-precision) floating-point number. Cannot be unsignedRanges are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and 2.2250738585072014E-308 to 1.7976931348623157E+308. If the number of Decimals is not set or 25 <= Decimals <= 53 stands for a double-precision floating point number
DECIMAL,
NUMERIC
An unpacked floating-point number. Cannot be unsignedBehaves like a CHAR column: unpacked means the number is stored as a string, using one character for each digit of the value. The decimal point, and, for negative numbers, the - sign is not counted in Length. If Decimals is 0, values will have no decimal point or fractional part. The maximum range of DECIMAL values is the same as for DOUBLE, but the actual range for a given DECIMAL column may be constrained by the choice of Length and Decimals. If Decimals is left out its set to 0. If Length is left out its set to 10. Note that in MySQL 3.22 the Length includes the sign and the decimal point
DATEA dateThe supported range is 1000-01-01 to 9999-12-31. MySQL displays DATE values in YYYY-MM-DD format
DATETIMEA date and time combinationThe supported range is 1000-01-01 00:00:00 to 9999-12-31 23:59:59. MySQL displays DATETIME values in YYYY-MM-DD HH:MM:SSformat
TIMESTAMPA timestampThe range is 1970-01-01 00:00:00 to sometime in the year 2037. MySQL displays TIMESTAMP values in YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format, depending on whether M is 14 (or missing), 12, 8 or 6, but allows you to assign values to TIMESTAMP columns using either strings or numbers. A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation because it is automatically set to the date and time of the most recent operation if you dont give it a value yourself
TIMEA timeThe range is -838:59:59 to 838:59:59. MySQL displays TIME values in HH:MM:SS format, but allows you to assign values to TIME columns using either strings or numbers
YEARA year in 2- or 4- digit formats (default is 4-digit)The allowable values are 1901 to 2155, and 0000 in the 4 year format and 1970-2069 if you use the 2 digit format (70-69). MySQL displays YEAR values in YYYY format, but allows you to assign values to YEAR columns using either strings or numbers. (The YEAR type is new in MySQL 3.22.)
CHARA fixed-length string that is always right-padded with spaces to the specified length when storedThe range of Length is 1 to 255 characters. Trailing spaces are removed when the value is retrieved. CHAR values are sorted and compared in case-insensitive fashion according to the default character set unless the BINARY keyword is given
VARCHARA variable-length string. Note: Trailing spaces are removed when the value is stored (this differs from the ANSI SQL specification)The range of Length is 1 to 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given
TINYBLOB,
TINYTEXT
A BLOB or TEXT column with a maximum length of 255 (2^8 - 1) characters
BLOB,
TEXT
A BLOB or TEXT column with a maximum length of 65535 (2^16 - 1) characters
MEDIUMBLOB,
MEDIUMTEXT
A BLOB or TEXT column with a maximum length of 16777215 (2^24 - 1) characters
LONGBLOB,
LONGTEXT
A BLOB or TEXT column with a maximum length of 4294967295 (2^32 - 1) characters
ENUMAn enumerationA string object that can have only one value, chosen from the list of values value1value2, ..., or NULL. An ENUM can have a maximum of 65535 distinct values.
SETA setA string object that can have zero or more values, each of which must be chosen from the list of values value1value2, ... A SET can have a maximum of 64 members