Sociogram: A Sample Application Exploring the Facebook SDK and the Graph API

I’ve recently been working on a few applications that integrate with Facebook. As a reference for myself and other developers building similar applications, I thought it would be useful to put together a sample application that demonstrates some commonly used integration scenarios and workflows when using the Facebook JavaScript SDK and the Graph API. So, Sociogram is a sample application that demonstrates how to:

  • Load the Facebook SDK
  • Login with Facebook
  • Request specific permissions
  • Revoke permissions
  • Get data (list of friends, mutual friends, feed items, etc.)
  • Post to the wall using your application’s custom UI or the Facebook dialogs
  • Listen to Facebook events such as status change, etc

The Graph API provides access to a lot more data and actions, but you are essentially always using the same API with a different path into the graph.

There are other examples out there, each of them built around different use cases. This application is built with Backbone.js using a single page architecture, but the code can easily be reused in a different context.

Running the Application

Click here to run the application in your browser.

Source Code

The source code is available in this GitHub repository.

Mobile App Version

In my next post, I will share a PhoneGap version of the same application (using the PhoneGap Facebook plugin).


This is a sample application, not a production application. Some trade-offs were made to keep the code generic, simple and readable.

  • Thanks for this and other great tutorials. Application looks awesome. Like the Facebook authentication.

    • Thirunavukkarasu


      Actually while i tried to deploy the application with my “app_id” the /me section is working as expected, but whereas the /me/friends api call is returning an empty page ? Is this because of v2 FB API change ? Please clarify!


      • Alex

        Hi, did you find out how to make the “/me/friends” api call works ?


        • Thirunavukkarasu

          No .. not yet Alex!

  • Charan

    Your tutorials are the best to get introduced to Backbone. Please keep them coming :)

  • Amir

    Great sample,
    Very helpful.
    Thank you.

  • Jan

    I see that you put the app id in the Facebook.js file, but where are you putting the app secret? Can you provide some guidance?

  • Dipock Das

    Thanks Christophe !!

  • Eduard

    this sample is great. might as well want to ask how change the tpl pages from html to php file. I tried changing it, but the links wont direct to php file. Please help

  • himilc

    any idea how to run it locally I’m pretty new to nodejs and backbone

  • Pingback: Sociogram Mobile: A Starter-Kit Application for PhoneGap and Facebook Integration | Christophe Coenraets()

  • Pingback: Sociogram: A Sample Application Exploring the Facebook SDK and the Graph API | Resource Mode()

  • This puts sliced bread to shame.

  • Shlook

    Thanks for this! I would like to know what should be changed in order to run it on my localhost (under Apache)

    Currently after clicking on “Login with Facebook” button, Facebook error message apear in the new window: “An error occurred. Please try again later.

    I tried to change facbook.js channelUrl var to point the location, but it doesn’t help.


  • Matt Tullett

    This a great starting point for getting started with backbone and facebook.

    I downloaded the code and setup everything like you have. I keep having a strange issue.
    If reload a page i get the error screen so i click retry and it works.

    I keep getting the error message :”An active access token must be used to query information about the current user.” even though i’m clearly logged in.

    The only things different is i’m running this on the Laravel framework and its using my app keys instead.

  • Matija

    Hi Christophe!
    Thanks for this tutorial! Have a question. What’s with javascript FB SDK, where is that file from? On regular FB web, JS SDK is included async from FB servers directly, and there’s no “offline” version. From where did you download this js file? (is it just take it from a browser after it’s downloaded async? )

    What happens if FB updates their FB SKD library? How can we update to Phonegap app as well?

    My other question, can we somehow use “longToken” with this set-up? From a mobile app perspective, we want our users to login once, and if possible, never again ( or once in few months ). Wouldn’t using standard web FB SDK library require user to login every 1h?

    Looking forward to your answers!

  • Great work. Thank you for sharing this nice tutorial.

  • How about Facebook SDK for PHP, I want to use it with php code please.

    • Dou Yi·

      Do you finally make the php version ? I also need to use it with php code.

  • hi

  • Pingback: Come realizzare il proprio sito web collegato con facebook()

  • AB

    Thanks for this great tutorial! On the demo I am not able to see my feed. Any advice?

  • Douglas K.M.

    Thanks for the sample apps but could you please do another one that combines backbone.js, Facebook and Basically a Sociogram that can save some data to and retrieve the data as in the case of the Employee Directory app. So that one can do a search through a collection and read the details of a selected item. This would make sense due to Facebook’s ownership of

  • Obaid

    The sample app is not working. When I click on ‘Login with Facebook’ it gives the following error: Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App’s settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App’s domains.

  • Note that this estimate not include taxes that may apply.
    Even though there are several companies that sell these services, it is very much
    important to do a background search of the company.
    When your fans click on the offer and if they are a real “passionate” group, chances
    are high that they’ll complete the CPA offer that you have.

  • Pingback: Sociogram: A Sample Application demonstrating AngularJS/Ionic and Facebook Integration | Christophe Coenraets()

  • This means that only certain ones are able to be encountered in this
    particular version. Some contain puzzle games, Adventure games
    as well as card games. mon trading cards, the Lee County sheriff’s office stated, according to
    an article then in the “Naples Daily News.

  • What’s up, all is going fine here and ofcourse every one is sharing facts, that’s
    in fact excellent, keep up writing.

  • Go for the GOLD BULLION, it is the true origin of money, the profession and possession of it should be first and foremost not the latter, seek ye first the Gold Bullion Profession and Possession, and with skilful management all things will be added unto thee, no
    bank loans or financing needed. Do not confirm that you want to send
    the gift, instead go through each of the tabs again, and select exactly the same friends in each window.
    The difficult with most of these formats relates to both cost and relative effectiveness.

  • Hi! I simply want to offer you a big thumbs up for the great information you have got right here on this post.
    I’ll be coming back to your site for more soon.

  • Hi Christophe,

    This is the first comment I do here, and trust me, I’ve been using this blog for a long time now.
    You are a big reference within my teams. Any issue I face there is something here to help me through.

    I have nothing more to say, just thank you for your mission and passion.

    You help to make the WWW better.

  • magnificent submit, very informative. I wonder why the
    opposite specialists of this sector do not realize this.
    You must proceed your writing. I’m sure, you have a
    huge readers’ base already!

  • Ahaa, its nice dialogue concerning this post
    at this place at this webpage, I have read all
    that, so now me also commenting at this place.

  • guys. what if I’m going to copy only the login and logout? any suggestions?

  • Pingback: Sociogram: A Pattern Software demonstrating AngularJS/Ionic and Fb Integration | PakUltimate()

  • Pingback: Sociogram: A Pattern Software demonstrating AngularJS/Ionic and Fb Integration | PakUltimate()

  • Pingback: Sociogram: A Pattern Software demonstrating AngularJS/Ionic and Fb Integration | PakUltimate()

  • bhathu

    hai sir.

    i want to login facebook and and once login means in index page i can able to view firstname,lastname,
    email,country username by using facebook graph api and it should store in databse..
    can you please guide or send some links..

  • Alexandre


    I read that the new facebook GRAPH API allow the apps to access only the friends who also use the app (and when I do /me/friends is that that happens). But I noticed that your APP is able to access list all of my friends?
    How is it done?

    Thanks a lot.

  • Danielgrant

    You may find out that only some of your customers are in areas that get news launch interest on Monday, while others are better at focusing on weekenders, and some might not be newsworthy at all. Before I Wake TRAILER

  • Pingback: Facebook login javascript sample code - Official Login()

  • Fabrics we use in our form; The first-class micro-interlock; flex-fit, anti-bacterial, it has a thermo-balance, and immediately drying. This gives you the freedom to move your soccer jerseys of the match; It is designed stylish enough to be worn on a daily basis. Our models are produced in two types as my special jerseys and other digital printed.

  • Amit Singh

    I do not see the friends API working on the run link shared by you.I need to show the mutual friends between my website users…has there been any change in the recent Facebook sdk for this

  • Iklas Dafadar Mca

    how to run application

  • There are lot of thing to know for coding.

    MPL pro mod apk