Skip to Main Content
Facebook Cookbook
book

Facebook Cookbook

by Jay Goldman
October 2008
Intermediate to advanced content levelIntermediate to advanced
434 pages
12h 7m
English
O'Reilly Media, Inc.
Content preview from Facebook Cookbook

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning PHP 5.3

Beginning PHP 5.3

Matt Doyle
HTML5 Geolocation

HTML5 Geolocation

Anthony T. Holdener

Publisher Resources

ISBN: 9780596156695Errata