O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Authenticating Users

Problem

How do I log a user into my Platform app?

Solution

Users have to be logged into Facebook in order for you to make API calls on their behalf, so Facebook provides an automated authentication process that you can initiate by redirecting users to http://www.facebook.com/login.php?api_key=1234567890&v=1.0 (where 1234567890 is your app’s API key). This URL can accept a few parameters, as documented in the Discussion.

Discussion

The process works like Figure 9-1.

User authentication flow

Figure 9-1. User authentication flow

Let’s walk through the steps. Users start off by visiting a Canvas page in your app without logging into Facebook first, as shown in Figure 9-2.

Canvas page with login message

Figure 9-2. Canvas page with login message

You can insert a standard Facebook login button anywhere you’d like with the following code:

<a href="http://www.facebook.com/login.php?api_key=1234567890
&v=1.0"><img src="http://static.ak.facebook.com/images/devsite/
facebook_login.gif"></a>

where 1234567890 is your app’s API key (which isn’t the same as your app’s ID; the API key can be found in the Facebook Developers app and is usually about 30 characters long, made up of letters and numbers). When users click on that button, they’ll get bumped over to a Facebook login page with your app’s name in it, as in Figure 9-3.

Figure 9-3. Facebook ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required