Creating a Session Key

Problem

I need a session key so that I can make subsequent API calls from my app’s server to Facebook. Where would I find such a thing?

Solution

If you’ve made a run down to the local Session Key Store and they’re all out of stock, try the Auth.createToken() and Auth.getSession() methods. Desktop apps need to call Auth.createToken() to generate a token, whereas web apps will receive one appended to their callback URL when users log in (see Authenticating Users for more info).

Discussion

Session keys were undergoing some changes as this book was being written, largely to make the process of adding new applications and authenticating easier for users. Facebook has modified a number of its API methods so that they no longer require a session key (meaning that you can call them on behalf of users without users needing to have added your app), and Facebook is moving in the direction of making it possible for users to try your app out and gradually grant it more permissions, rather than a single, complex authentication page. Facebook is working toward having the following methods not require a key:

  • Auth.createToken()

  • Auth.getSession()

  • Fbml.refreshImgSrc()

  • Fbml.refreshRefUrl()

  • Fbml.setRefHandle()

  • Marketplace.createListing()

  • Marketplace.getCategories()

  • Marketplace.getSubCategories()

  • Marketplace.removeListing()

  • Notifications.send()

  • Notifications.sendEmail()

  • Pages.getInfo()

  • Pages.isAppAdded()

  • Photos.addTag()

  • Photos.createAlbum()

  • Photos.upload()

  • Profile.getFBML()

  • Profile.setFBML()

  • Users.hasAppPermission() ...

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.