Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change.Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.

User level

Required products

Sample files

When you develop and deploy an app or game on Facebook you need to invoke the Facebook API to login as well as to get details about the user, friends, photos, and other information. There are currently several official SDKs that you can use to perform such tasks via the Facebook Graph API. This article will guide you through the basics of using the JavaScript SDK with ActionScript 3.

The Facebook API is simple and supports rapid extensibility without API changes, via the Graph API.

A good place to begin is with these three Facebook JavaScript API calls:

FB.init – initialize Facebook API

FB.login - login to Facebook

FB.api - perform a Graph API call on Facebook

You can call the JavaScript wrappers from ActionScript using flash.external.ExternalInterface. This provides access to the Facebook API from the Flash runtime and enables you to be always up-to-date whenever Facebook changes or updates their official JavaScript APIs (see Figure 1).

Step 4: Initialize the Facebook JS SDK

To initialize the SDK, include the following code within your HTML <head> element and replace YOUR_APP_ID with the App ID you noted in the previous step. (If you are using Flash Builder, add this code to index.template.html.)

Now you have set up basic communication from Flash Player to JavaScript to Facebook and back.

The code above calls the FB.login function and creates an anonymous function callback, which checks for the actual authResponse status. It then calls FB.api function, which calls the Facebook Graph API. To get information about the current user, it simply passes '/me' as a parameter.

Once you have logged in, you can just call FB.api("command") alone without the need for FB.login; for example: