The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing Facebook Login.
Take a look at the Getting Started guide for full information about features and usage.
The following code will load and initialize the JavaScript SDK with the most common options. Replace YOUR_APP_ID with your App ID from the App Dashboard, and WWW.YOUR_DOMAIN.COM with the path to your Channel File.
This code works best when placed directly after the opening <body> tag.
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'YOUR_APP_ID', // App ID from the app dashboard
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Full details on initializing the SDK can be found in the Getting Started section.
Initialize the library.
Synchronous accessor for the current authResponse.
Find out the current status from the server, and get a session if the user is connected.
Login/Authorize/Permissions.
Logout the user in the background.
Subscribe to a given event name, invoking your callback function whenever the event is fired.
Removes subscribers, inverse of FB.Event.subscribe.
Parse and render XFBML markup in the document.
Controls which static resources are flushed to the browser early.
Controls how statistics are collected on resources used by your application, with the intent to influence whether those resources will be fetched to the browser early, or to turn off Prefetching completely.
Hides a Flash Element, used in conjunction with hideFlashCallback.
Tells Facebook to scroll to a specific location in the iframe of your canvas page.
Starts or stops a timer which resizes your iframe every few milliseconds.
Reports that the page is now usable by the user, for collecting performance metrics.
Tells Facebook to resize your iframe.
Registers the callback for inline processing (i.e. without page reload) of user actions, such as clicks on Live Ticker game stories.
Display a Flash Element, used in conjunction with hideFlashCallback.
When using setDoneLoading, controls the page load timer.
When using setDoneLoading, controls the page load timer.