Facebook Developers
DocumentationSupportBlogAppsLog In
  • Getting Started
  • Core Concepts
  • Advanced Topics
  • SDK Reference
    • JavaScript SDK
    • PHP SDK
    • iOS SDK
    • Android SDK
  • Tools
  • Core Methods
    • FB.api
    • FB.init
    • FB.ui
  • Auth Methods
    • FB.getAuthResponse
    • FB.getLoginStatus
    • FB.getSession
    • FB.login
    • FB.logout
  • Event Handling
    • FB.Event.subscribe
    • FB.Event.unsubscribe
  • XFBML Methods
    • FB.XFBML.parse
  • Canvas Methods
    • FB.Canvas.Prefetcher.addStaticResource
    • FB.Canvas.Prefetcher.setCollectionMode
    • FB.Canvas.getPageInfo
    • FB.Canvas.hideFlashElement
    • FB.Canvas.scrollTo
    • FB.Canvas.setAutoGrow
    • FB.Canvas.setDoneLoading
    • FB.Canvas.setSize
    • FB.Canvas.setUrlHandler
    • FB.Canvas.showFlashElement
    • FB.Canvas.startTimer
    • FB.Canvas.stopTimer

FB.login

SDK Reference › JavaScript SDK › FB.login
As of December 13th, 2011, the JavaScript SDK now only supports OAuth 2.0 for authentication. The ability to enable OAuth 2.0 in the JS SDK was first introduced in July. All apps were given until October 1, 2011 to test and migrate. With this change, please ensure that you replaced response.session with response.authResponse. To ask for permissions, you must use scope instead of perms. Read more about the specific changes here.

Overview

Calling FB.login prompts the user to authenticate your application using the OAuth Dialog.

Calling FB.login results in the JS SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.

Example

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });

Permissions

By default, calling FB.login will attempt to authenticate the user with only the basic permissions. If you want one or more additional permissions, call FB.login with an option object, and set the scope parameter with a comma-separated list of the permissions you wish to request from the user.

 FB.login(function(response) {
   // handle the response
 }, {scope: 'email,user_likes'});

Asking for more permissions decreases the number of users who will choose to authenticate your application. As such, you should ask for as few permissions as possible the first time you want a user to authenticate your app.

If you need to collect more permissions from users who have already authenticated with your application, call FB.login again with the permissions you want the user to grant. In the authentication dialog, the user will only ever be asked for permissions they have not already granted.

Parameters

NameTypeDescription
cbFunction

The callback function.

optsObject

(optional) Options to modify login behavior.

Name Type Description
scope String Comma separated list of Extended permissions
Updated about 3 months ago
Facebook © 2012 · English (US)
AboutCareersPlatform PoliciesPrivacy Policy