The Graph API gives you access to public information. If you need more you have to have an access token. There are a couple of ways of gaining one, but first you need to create an application and get an App ID & App Secret.

  1. Create application here: http://www.facebook.com/developers/
  2. Click Setup Application in the upper right and follow the steps
  3. Create a link to the auth page:
    1. https://graph.facebook.com/oauth/authorize?client_id=APP-ID-HERE&redirect_uri=http://URL-TO-REDIRECT-TO&scope=read_stream&type=user_agent
    2. client_id should be set to your application ID. You can find it on this page.
    3. redirect_uri is the URL you want Facebook to redirect to with the access token in the URL in this format: http://example.com/facebook-app.php#access_token=452452ACCESS-TOKEN-HERE
  4. When the user clicks the link they will be brought to a Facebook Allow/Deny app page. If you need additional permissions such as access to feeds you’ll have to configure scope (&scope=read_stream,read_friendlist). Read here for more information.
  5. After the user allows the app they will be forwarded to the redirect_uri and the access token will be in the URL in the format mentioned above.

This code can be used to pull the access token out of the URL:

?View Code JAVASCRIPT
var url = location.href;
var access_token = url.split('=')[1].split('&')[0];
/* Assumes default format without any parameters/variables added to the url by the user */

The access token can be accessed via the “access_token” variable