Skip to content

Instantly share code, notes, and snippets.

@aarongrando
Created January 18, 2012 19:53

Revisions

  1. @invalid-email-address Anonymous revised this gist Jan 18, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,6 @@ $(function() {
    xfbml : true
    });

    FB.Canvas.setAutoResize()

    FB.getLoginStatus(function (response) {

    if (response.authResponse) { // if the user is authorized...
  2. @invalid-email-address Anonymous created this gist Jan 18, 2012.
    59 changes: 59 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    $(function() {

    // Depends on: jQuery, jQuery UI core & widgets (for the autocomplete method)
    // Assumes you're already including the FB JS SDK asynchronously...

    window.fbAsyncInit = function() {

    FB.init({
    appId : 'xxxxxxxxxxxxxxxxxx', // App ID
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    oauth : true,
    xfbml : true
    });

    FB.Canvas.setAutoResize()

    FB.getLoginStatus(function (response) {

    if (response.authResponse) { // if the user is authorized...
    var accessToken = response.authResponse.accessToken
    var tokenUrl = "https://graph.facebook.com/me/friends?access_token=" + accessToken + "&callback=?"

    // Place <input id="name" /> and <input id="fbuid" /> into HTML

    $("#name").autocomplete({
    source: function(request, add) {
    $this = $(this)
    // Call out to the Graph API for the friends list
    $.ajax({
    url: tokenUrl,
    dataType: "jsonp",
    success: function(results){
    // Filter the results and return a label/value object array
    var formatted = [];
    for(var i = 0; i< results.data.length; i++) {
    if (results.data[i].name.toLowerCase().indexOf($('#name').val().toLowerCase()) >= 0)
    formatted.push({
    label: results.data[i].name,
    value: results.data[i].id
    })
    }
    add(formatted);
    }
    });
    },
    select: function(event, ui) {
    // Fill in the input fields
    $('#name').val(ui.item.label)
    $('#fbuid').val(ui.item.value)
    // Prevent the value from being inserted in "#name"
    return false;
    },
    minLength: 2
    });
    }
    });
    };
    });