Sunday, October 20, 2013

Facebook API Hello World

After working through the Facebook API Getting Started guide I decided to write an even simpler Hello World application that also displays some debugging information. This is my first Facebook Application.

<head><title>Facebook API Hello World</title></head>
<script type="text/javascript">
  window.fbAsyncInit = function() {
      appId: '222165227950143' /* registered application id */,
      status: true /* check the login status */,
      cookie: true /* set the session cookie */,
      xfbml: true /* enable social plugins */

    // get the initial login status

  // Load the SDK Asynchronously
  (function(d, s, id){
    if (d.getElementById(id)) {return;}
    var js, fjs = d.getElementsByTagName(s)[0];
    js = d.createElement(s); = id;
    js.src = "//";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

  function onLogin(response) {
    document.getElementById('login-status').innerHTML = response.status;

    if(response.status === 'connected') {
      var uid = response.authResponse.userID;
      document.getElementById('user-id').innerHTML = uid;

  function readName() {
      function(response) {
        var e = document.getElementById('user-name');
        if(!response) {
          e.innerHTML = '<i>no object</i>';
        } else if(response.error) {
          e.innerHTML = '<i>Error: ' + response.error.message + '</i>';
        } else {
          e.innerHTML =;

<p>When we are connected to facebook, read the name of the current user and
display it here.  If you would like to read the name of the current user again
or before being connected to facebook, press the "read name" button.</p>

<!-- -->

(Status: <span id="login-status"><i>???</i></span>)
(User ID: <span id="user-id"><i>???</i></span>)
(onLogin calls: <span id="onlogin-count">0</span>)

<input type="button" value="read name" onclick="readName()">
<span id="user-name"><i>???</i></span>
(readName calls: <span id="user-count">0</span>)


This is my first time working with the Facebook API. I like how all the API calls execute in the background, and not block the browser.


  1. Facebook pulls a staggering 29 % of all the global online traffic to their site - another staggering number of 510 million users. Any opportunistic internet marketer must learn how to market on Facebook to generate leads for their mlm business.More about the author

  2. This means the original account holder will not notice anything going on until when you either change their passwords, make other changes to their account like posting and commenting or changing their profile picture and information. Facebook account hacken

  3. Our tool has been loaded with a list that contains billions of combinations already, from simple to complex words, from letters to combinations, it has almost everything Blue Portal

  4. This article I expectation will be most useful and give you profitable understanding on protecting your own data and companions! Spread the news!