Main

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).

Disclaimer

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

Share this Article:

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

  1. Mike February 11, 2013 at 3:14 am #

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

  2. Charan February 11, 2013 at 7:07 pm #

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

  3. Amir February 12, 2013 at 11:59 pm #

    Great sample,
    Very helpful.
    Thank you.

  4. Jan February 13, 2013 at 6:36 am #

    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?

  5. Dipock Das February 18, 2013 at 7:25 pm #

    Thanks Christophe !!

  6. Eduard March 19, 2013 at 12:19 pm #

    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

  7. himilc March 19, 2013 at 1:35 pm #

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

  8. Travis March 22, 2013 at 8:59 pm #

    This puts sliced bread to shame.

  9. Shlook April 9, 2013 at 8:36 am #

    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.

    Thanks!

  10. Matt Tullett May 13, 2013 at 6:28 pm #

    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.

  11. Matija May 21, 2013 at 4:35 am #

    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!
    Thanks,
    Matija

  12. Rajkumar June 9, 2013 at 8:46 am #

    Great work. Thank you for sharing this nice tutorial.

Trackbacks/Pingbacks

  1. Sociogram Mobile: A Starter-Kit Application for PhoneGap and Facebook Integration | Christophe Coenraets - March 21, 2013

    [...] few weeks ago I shared Sociogram, a sample application that demonstrates how to use the Facebook JavaScript SDK and the Graph API. A [...]

  2. Sociogram: A Sample Application Exploring the Facebook SDK and the Graph API | Resource Mode - March 22, 2013

    [...] : Click here This entry was posted in Development, Open Source Framework on March 22, 2013 by [...]

Leave a Reply


7 − = 4

Powered by WordPress. Designed by Woo Themes