Spending my days programming virtual worlds for The Electric Sheep Company. Spending nights and weekends on BlitzPick for Super + Fun. I also enjoy quilting, reading, and singing in the shower.

ccarella:


We continue to make great progress on BlitzPick Baseball.
There are just 25 more days until Major League Baseball’s opening day. Head over to BlitzPick Baseball to sign up for our Facebook fan page and bookmark our app!

ccarella:

We continue to make great progress on BlitzPick Baseball.

There are just 25 more days until Major League Baseball’s opening day. Head over to BlitzPick Baseball to sign up for our Facebook fan page and bookmark our app!

Wednesday, March 10th, 2010

reblogged from : ChrisCarella.Com

Creating a facebook bookmark button without a session

Last night we put up a “Coming Soon” page for Super + Fun’s new Facebook app, BlitzPick Baseball which will be launching later this month. We wanted to start letting people bookmark the app and sign up as fans. The idea was to point the app to the placeholder we put up on blitzpick.com.

However, <fb:bookmark> tag doesn’t work without an active session. An active session would require bumping people over to a login page before they can view the coming soon page. We didn’t want that. The javascript option, FB.Connect.showBookmarkDialog, works fine in a connect page because it opens a login popup showing the bookmark dialog. Neither solution works out of the box for an iframe app that doesn’t require the user to authorize the app first.

Instead, I used a custom button and javascript so that the ‘Add Bookmark’ button always appears, regardless of whether the user is logged into facebook, viewing the app page, or viewing the connect site on blitzpick.com directly. As a bonus, the button gets replaced with text if the user is connected and has already bookmarked the app.

When the page loads, I try to get a session and determine if the user is viewing the app from an iframe canvas.

// Called shortly after page loads, after FB.Facebook.init
function init() {
  session = FB.Facebook.apiClient.get_session();
  canvas = FB.Facebook.get_isInCanvas();
  updateBookmarkPrompt();
  // If the user was redirected to a login page after clicking
  // the bookmark button, automatically prompt them on return
  if (window.location.search.indexOf('addBookmark') >= 0) {
    addBookmark();
  }
}

When the user clicks the ‘Add Bookmark’ button, I call FB.Connect.showBookmarkDialog if the user is in a connect page or if the user has authorized app. If the user is viewing the iframe app but hasn’t authorized the app, I redirect them to the login page. The next url has an ‘addBookmark’ parameter appended to it, so upon return I can automatically open the bookmark dialog, as shown in the init function above..

// Called when user clicks the 'Add Bookmark' button.  Redirect to
// login first if user is in an iframe app but hasn't authorized
// the app yet.
function addBookmark() {
  // In an iframe, but we don't have a session yet.  Redirect
  // to login page and open bookmark dialog upon return.
  if (canvas && !session) { 
    redirect = 'http://www.facebook.com/login.php?api_key=' + api_key
                              + '&extern=1&fbconnect=1&v=1.0'
                              + '&next=' + canvas_page + escape("?addBookmark")
                              + '&cancel_url=' + canvas_page;
    self.parent.location = redirect;
  } 

  // If the user is in a connect page or has a session already
  // in an iframe app, show the bookmark dialog with javascript.  
  // If user is on a connect page, this call will open an 
  // iframe to prompt a login first if necessary.
  else {
    FB.Connect.showBookmarkDialog(updateBookmarkPrompt);
  }
}

To top it all off, I check if the user has bookmarked the app after they close the dialog and replace the button with text if they have.

// Replace the 'Add Bookmark' button with thank-you text if we 
// see the user has already bookmarked the app
function updateBookmarkPrompt() {
  if (session != null) {
    FB.Facebook.apiClient.fql_query(
      "SELECT bookmarked FROM permissions WHERE uid=" + session.uid,
      function(rows) {
        if (rows[0].bookmarked == 1) {
          document.getElementById("bookmark").innerHTML 
               = "Thanks for bookmarking this app.";
        }
      }
    );
  }
}

View the full source on github.

See it in action at http://becarella.github.com/facebook/bookmark and http://apps.facebook.com/becarella/bookmark.

Friday, March 5th, 2010

explodingdog:

This is great coffee

explodingdog:

This is great coffee

Friday, March 5th, 2010

reblogged from : explodingdog

Wednesday, March 3rd, 2010

Friday, February 19th, 2010

Test controllers with Facebooker Mock Sessions

To avoid login redirects when testing controllers that use Facebooker’s ensure_authenticated_to_facebook before_filter, use a mock session:

    get(:index, {}, {
      :facebook_session => Facebooker::MockSession.create})
    assert_response :success

Friday, February 12th, 2010

Sunday, January 24th, 2010

Tuesday, December 29th, 2009

Monday, December 21st, 2009