com.parse

## Class ParseFacebookUtils

- java.lang.Object
- - com.parse.ParseFacebookUtils

    public final class ParseFacebookUtils
    extends Object

Provides a set of utilities for using Parse with Facebook. To use `ParseFacebookUtils`, you must add the Facebook Android SDK to your project.

### Method Summary

Methods
`static void` `extendAccessToken(com.parse.ParseUser user, Context context, com.parse.SaveCallback callback)` Deprecated. This is now handled automatically by the Facebook SDK.
`static boolean` `extendAccessTokenIfNeeded(com.parse.ParseUser user, Context context, com.parse.SaveCallback callback)` Deprecated. This is now handled automatically by the Facebook SDK.
`static void` `finishAuthentication(int requestCode, int resultCode, Intent data)` Completes authentication after the Facebook app returns an activity result.
`static Facebook` `getFacebook()` Deprecated. Please use `ParseFacebookUtils.getSession()` and related Facebook SDK 3.0+ APIs instead.
`static Session` `getSession()`
`static void` `initialize()` Deprecated. Please use `ParseFacebookUtils.initialize(Context)` instead.
`static void` `initialize(Context context)` Initializes Facebook for use with Parse.
`static void` `initialize(Context context, String appId)` Initializes Facebook with a custom `appId` for use with Parse.
`static void` `initialize(String appId)` Deprecated. Please use `ParseFacebookUtils.initialize(Context, String)` instead.
`static boolean` `isLinked(com.parse.ParseUser user)`
`static void` `link(com.parse.ParseUser user, Activity activity)` Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity)` instead.
`static void` `link(com.parse.ParseUser user, Activity activity, int activityCode)` Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity, int)` instead.
`static void` `link(com.parse.ParseUser user, Activity activity, int activityCode, com.parse.SaveCallback callback)`
`static void` `link(com.parse.ParseUser user, Activity activity, com.parse.SaveCallback callback)`
`static void` `link(com.parse.ParseUser user, Collection<String> permissions, Activity activity)` Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity)` instead.
`static void` `link(com.parse.ParseUser user, Collection<String> permissions, Activity activity, int activityCode)` Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)` instead.
`static void` `link(com.parse.ParseUser user, Collection<String> permissions, Activity activity, int activityCode, com.parse.SaveCallback callback)` Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user.
`static void` `link(com.parse.ParseUser user, Collection<String> permissions, Activity activity, com.parse.SaveCallback callback)` Links a user using the default activity code if single sign-on is enabled.
`static void` `link(com.parse.ParseUser user, String facebookId, String accessToken, Date expirationDate)` Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, String, String, java.util.Date)` instead.
`static void` `link(com.parse.ParseUser user, String facebookId, String accessToken, Date expirationDate, com.parse.SaveCallback callback)` Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user.
`static Task<Void>` `linkInBackground(com.parse.ParseUser user, Activity activity)`
`static Task<Void>` `linkInBackground(com.parse.ParseUser user, Activity activity, int activityCode)`
`static Task<Void>` `linkInBackground(com.parse.ParseUser user, Collection<String> permissions, Activity activity)`
`static Task<Void>` `linkInBackground(com.parse.ParseUser user, Collection<String> permissions, Activity activity, int activityCode)` Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user.
`static Task<Void>` `linkInBackground(com.parse.ParseUser user, String facebookId, String accessToken, Date expirationDate)` Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user.
`static void` `logIn(Activity activity, int activityCode, com.parse.LogInCallback callback)`
`static void` `logIn(Activity activity, com.parse.LogInCallback callback)`
`static void` `logIn(Collection<String> permissions, Activity activity, int activityCode, com.parse.LogInCallback callback)` Logs in a ParseUser using Facebook for authentication.
`static void` `logIn(Collection<String> permissions, Activity activity, com.parse.LogInCallback callback)` Logs in a user using the default activity code if single sign-on is enabled.
`static void` `logIn(String facebookId, String accessToken, Date expirationDate, com.parse.LogInCallback callback)` Logs in a ParseUser using Facebook for authentication.
`static Task<com.parse.ParseUser>` `logInInBackground(Collection<String> permissions, Activity activity, int activityCode)` Logs in a ParseUser using Facebook for authentication.
`static Task<com.parse.ParseUser>` `logInInBackground(String facebookId, String accessToken, Date expirationDate)` Logs in a ParseUser using Facebook for authentication.
`static void` `saveLatestSessionData(com.parse.ParseUser user)` Deprecated. Please use `ParseFacebookUtils.saveLatestSessionDataInBackground(ParseUser)` instead.
`static void` `saveLatestSessionData(com.parse.ParseUser user, com.parse.SaveCallback callback)` Saves the latest session data to the user.
`static Task<Void>` `saveLatestSessionDataInBackground(com.parse.ParseUser user)` Saves the latest session data to the user.
`static boolean` `shouldExtendAccessToken(com.parse.ParseUser user)` Deprecated. This is now handled automatically by the Facebook SDK.
`static void` `unlink(com.parse.ParseUser user)` Unlinks a user from a Facebook account.
`static Task<Void>` `unlinkInBackground(com.parse.ParseUser user)` Unlinks a user from a Facebook account in the background.
`static void` `unlinkInBackground(com.parse.ParseUser user, com.parse.SaveCallback callback)` Unlinks a user from a Facebook account in the background.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### getFacebook

    @Deprecated
    public static Facebook getFacebook()

Deprecated. Please use `ParseFacebookUtils.getSession()` and related Facebook SDK 3.0+ APIs instead.

#### getSession

    public static Session getSession()

Returns:
  The active Facebook session associated with the logged in ParseUser, or null if there is none.

#### isLinked

    public static boolean isLinked(com.parse.ParseUser user)

Returns:
  `true` if the user is linked to a Facebook account.

#### initialize

    @Deprecated
    public static void initialize()

Deprecated. Please use `ParseFacebookUtils.initialize(Context)` instead.

#### initialize

    public static void initialize(Context context)

Initializes Facebook for use with Parse.

IMPORTANT: If you choose to enable single sign-on, you must override the `Activity.onActivityResult(int, int, android.content.Intent)` method to invoke `ParseFacebookUtils.finishAuthentication(int, int, Intent)`.

Parameters:
  `context` - The application context.
See Also:
  `ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)`, `ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)`

#### initialize

    @Deprecated
    public static void initialize(String appId)

Deprecated. Please use `ParseFacebookUtils.initialize(Context, String)` instead.

#### initialize

    public static void initialize(Context context,
                  String appId)

Initializes Facebook with a custom `appId` for use with Parse.

This method is only required if you intend to use a different `appId` than is defined by `com.facebook.sdk.ApplicationId` in your `AndroidManifest.xml`. You may also invoke this method more than once if you need to change the appId.

IMPORTANT: If you choose to enable single sign-on, you must override the `Activity.onActivityResult(int, int, android.content.Intent)` method to invoke `ParseFacebookUtils.finishAuthentication(int, int, Intent)`.

Parameters:
  `context` - The application context.
  `appId` - The Facebook appId for your application.
See Also:
  `ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)`, `ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)`

#### unlink

    public static void unlink(com.parse.ParseUser user)
                       throws com.parse.ParseException

Unlinks a user from a Facebook account. Unlinking a user will save the user's data.

Parameters:
  `user` - The user to unlink from Facebook.
Throws:
  `com.parse.ParseException`

#### unlinkInBackground

    public static Task<Void> unlinkInBackground(com.parse.ParseUser user)

Unlinks a user from a Facebook account in the background. Unlinking a user will save the user's data.

Parameters:
  `user` - The user to unlink from Facebook.
Returns:
  A Task that will be resolved when unlinking has completed.

#### unlinkInBackground

    public static void unlinkInBackground(com.parse.ParseUser user,
                          com.parse.SaveCallback callback)

Unlinks a user from a Facebook account in the background. Unlinking a user will save the user's data.

Parameters:
  `user` - The user to unlink from a Facebook account.
  `callback` - Callback for notifying when unlinking is complete.

#### linkInBackground

    public static Task<Void> linkInBackground(com.parse.ParseUser user,
                              String facebookId,
                              String accessToken,
                              Date expirationDate)

Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user. This method allows you to handle getting access tokens for the user yourself, rather than delegating to the Facebook SDK.

Parameters:
  `user` - The user to link to a Facebook account.
  `facebookId` - The facebook ID of the user being linked.
  `accessToken` - The access token for the user.
  `expirationDate` - The expiration date of the access token.
Returns:
  A task that will be resolved when linking is completed.

#### link

    @Deprecated
    public static void link(com.parse.ParseUser user,
                       String facebookId,
                       String accessToken,
                       Date expirationDate)

Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, String, String, java.util.Date)` instead.

#### link

    public static void link(com.parse.ParseUser user,
            String facebookId,
            String accessToken,
            Date expirationDate,
            com.parse.SaveCallback callback)

Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user. This method allows you to handle getting access tokens for the user yourself, rather than delegating to the Facebook SDK.

Parameters:
  `user` - The user to link to a Facebook account.
  `facebookId` - The facebook ID of the user being linked.
  `accessToken` - The access token for the user.
  `expirationDate` - The expiration date of the access token.
  `callback` - Callback for notifying when the new authentication data has been saved to the user.

#### linkInBackground

    public static Task<Void> linkInBackground(com.parse.ParseUser user,
                              Collection<String> permissions,
                              Activity activity,
                              int activityCode)

Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user. This method delegates to the Facebook SDK's `authenticate()` method.

IMPORTANT: Note that single sign-on authentication will not function correctly if you do not include a call to the `finishAuthentication()` method in your onActivityResult() function! Please see below for more information.

From the Facebook SDK documentation:

Starts either an Activity or a dialog which prompts the user to log in to Facebook and grant the requested permissions to the given application.

This method will, when possible, use Facebook's single sign-on for Android to obtain an access token. This involves proxying a call through the Facebook for Android stand-alone application, which will handle the authentication flow, and return an OAuth access token for making API calls.

Because this process will not be available for all users, if single sign-on is not possible, this method will automatically fall back to the OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled by Facebook in an embedded WebView, not by the client application. As such, the dialog makes a network request and renders HTML content rather than a native UI. The access token is retrieved from a redirect to a special URL that the WebView handles.

Parameters:
  `user` - The user to link to a Facebook account.
  `permissions` - A list of permissions to be used when logging in. Many of these constants are defined here: `ParseFacebookUtils.Permissions`.
  `activity` - The Android activity in which we want to display the authorization dialog.
  `activityCode` - Single sign-on requires an activity result to be called back to the client application -- if you are waiting on other activities to return data, pass a custom activity code here to avoid collisions.
Returns:
  A Task that will be resolved when linking is completed.

#### linkInBackground

    public static Task<Void> linkInBackground(com.parse.ParseUser user,
                              Collection<String> permissions,
                              Activity activity)

See Also:
  `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)`, `FacebookAuthenticationProvider.DEFAULT_AUTH_ACTIVITY_CODE`

#### linkInBackground

    public static Task<Void> linkInBackground(com.parse.ParseUser user,
                              Activity activity,
                              int activityCode)

See Also:
  `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)`

#### linkInBackground

    public static Task<Void> linkInBackground(com.parse.ParseUser user,
                              Activity activity)

See Also:
  `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)`, `FacebookAuthenticationProvider.DEFAULT_AUTH_ACTIVITY_CODE`

#### link

    public static void link(com.parse.ParseUser user,
            Collection<String> permissions,
            Activity activity,
            int activityCode,
            com.parse.SaveCallback callback)

Links a ParseUser to a Facebook account, allowing you to use Facebook for authentication, and providing access to Facebook data for the user. This method delegates to the Facebook SDK's `authenticate()` method.

IMPORTANT: Note that single sign-on authentication will not function correctly if you do not include a call to the `finishAuthentication()` method in your onActivityResult() function! Please see below for more information.

From the Facebook SDK documentation:

Starts either an Activity or a dialog which prompts the user to log in to Facebook and grant the requested permissions to the given application.

This method will, when possible, use Facebook's single sign-on for Android to obtain an access token. This involves proxying a call through the Facebook for Android stand-alone application, which will handle the authentication flow, and return an OAuth access token for making API calls.

Because this process will not be available for all users, if single sign-on is not possible, this method will automatically fall back to the OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled by Facebook in an embedded WebView, not by the client application. As such, the dialog makes a network request and renders HTML content rather than a native UI. The access token is retrieved from a redirect to a special URL that the WebView handles.

Parameters:
  `user` - The user to link to a Facebook account.
  `permissions` - A list of permissions to be used when logging in. Many of these constants are defined here: `ParseFacebookUtils.Permissions`.
  `activity` - The Android activity in which we want to display the authorization dialog.
  `activityCode` - Single sign-on requires an activity result to be called back to the client application -- if you are waiting on other activities to return data, pass a custom activity code here to avoid collisions.
  `callback` - Callback for notifying the calling application when the Facebook authentication has completed, failed, or been canceled.

#### link

    public static void link(com.parse.ParseUser user,
            Collection<String> permissions,
            Activity activity,
            com.parse.SaveCallback callback)

Links a user using the default activity code if single sign-on is enabled.

See Also:
  `ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)`

#### link

    @Deprecated
    public static void link(com.parse.ParseUser user,
                       Collection<String> permissions,
                       Activity activity,
                       int activityCode)

Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)` instead.

#### link

    @Deprecated
    public static void link(com.parse.ParseUser user,
                       Collection<String> permissions,
                       Activity activity)

Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity)` instead.

#### link

    public static void link(com.parse.ParseUser user,
            Activity activity,
            int activityCode,
            com.parse.SaveCallback callback)

See Also:
  `ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)`

#### link

    public static void link(com.parse.ParseUser user,
            Activity activity,
            com.parse.SaveCallback callback)

See Also:
  `ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)`

#### link

    @Deprecated
    public static void link(com.parse.ParseUser user,
                       Activity activity,
                       int activityCode)

Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity, int)` instead.

#### link

    @Deprecated
    public static void link(com.parse.ParseUser user,
                       Activity activity)

Deprecated. Please use `ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity)` instead.

#### logInInBackground

    public static Task<com.parse.ParseUser> logInInBackground(String facebookId,
                                              String accessToken,
                                              Date expirationDate)

Logs in a ParseUser using Facebook for authentication. If a user for the given Facebook credentials does not already exist, a new user will be created. This method allows you to handle getting access tokens for the user yourself, rather than delegating to the Facebook SDK.

Parameters:
  `facebookId` - The facebook ID of the user being linked.
  `accessToken` - The access token for the user.
  `expirationDate` - The expiration date of the access token.
Returns:
  A Task that will be resolved when logging in is completed.

#### logIn

    public static void logIn(String facebookId,
             String accessToken,
             Date expirationDate,
             com.parse.LogInCallback callback)

Logs in a ParseUser using Facebook for authentication. If a user for the given Facebook credentials does not already exist, a new user will be created. This method allows you to handle getting access tokens for the user yourself, rather than delegating to the Facebook SDK.

Parameters:
  `facebookId` - The facebook ID of the user being linked.
  `accessToken` - The access token for the user.
  `expirationDate` - The expiration date of the access token.
  `callback` - Callback for notifying when the new authentication data has been saved to the user.

#### logInInBackground

    public static Task<com.parse.ParseUser> logInInBackground(Collection<String> permissions,
                                              Activity activity,
                                              int activityCode)

Logs in a ParseUser using Facebook for authentication. If a user for the given Facebook credentials does not already exist, a new user will be created. This method delegates to the Facebook SDK's `authenticate()` method.

IMPORTANT: Note that single sign-on authentication will not function correctly if you do not include a call to the `finishAuthentication()` method in your onActivityResult() function! Please see below for more information.

From the Facebook SDK documentation:

Starts either an Activity or a dialog which prompts the user to log in to Facebook and grant the requested permissions to the given application.

This method will, when possible, use Facebook's single sign-on for Android to obtain an access token. This involves proxying a call through the Facebook for Android stand-alone application, which will handle the authentication flow, and return an OAuth access token for making API calls.

Because this process will not be available for all users, if single sign-on is not possible, this method will automatically fall back to the OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled by Facebook in an embedded WebView, not by the client application. As such, the dialog makes a network request and renders HTML content rather than a native UI. The access token is retrieved from a redirect to a special URL that the WebView handles.

Parameters:
  `permissions` - A list of permissions to be used when logging in. Many of these constants are defined here: `ParseFacebookUtils.Permissions`.
  `activity` - The Android activity in which we want to display the authorization dialog.
  `activityCode` - Single sign-on requires an activity result to be called back to the client application -- if you are waiting on other activities to return data, pass a custom activity code here to avoid collisions.
Returns:
  A Task that will be resolved when logging in is completed.

#### logIn

    public static void logIn(Collection<String> permissions,
             Activity activity,
             int activityCode,
             com.parse.LogInCallback callback)

Logs in a ParseUser using Facebook for authentication. If a user for the given Facebook credentials does not already exist, a new user will be created. This method delegates to the Facebook SDK's `authenticate()` method.

IMPORTANT: Note that single sign-on authentication will not function correctly if you do not include a call to the `finishAuthentication()` method in your onActivityResult() function! Please see below for more information.

From the Facebook SDK documentation:

Starts either an Activity or a dialog which prompts the user to log in to Facebook and grant the requested permissions to the given application.

This method will, when possible, use Facebook's single sign-on for Android to obtain an access token. This involves proxying a call through the Facebook for Android stand-alone application, which will handle the authentication flow, and return an OAuth access token for making API calls.

Because this process will not be available for all users, if single sign-on is not possible, this method will automatically fall back to the OAuth 2.0 User-Agent flow. In this flow, the user credentials are handled by Facebook in an embedded WebView, not by the client application. As such, the dialog makes a network request and renders HTML content rather than a native UI. The access token is retrieved from a redirect to a special URL that the WebView handles.

Parameters:
  `permissions` - A list of permissions to be used when logging in. Many of these constants are defined here: `ParseFacebookUtils.Permissions`.
  `activity` - The Android activity in which we want to display the authorization dialog.
  `activityCode` - Single sign-on requires an activity result to be called back to the client application -- if you are waiting on other activities to return data, pass a custom activity code here to avoid collisions.
  `callback` - Callback for notifying the calling application when the Facebook authentication has completed, failed, or been canceled.

#### logIn

    public static void logIn(Activity activity,
             int activityCode,
             com.parse.LogInCallback callback)

See Also:
  `ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)`

#### logIn

    public static void logIn(Collection<String> permissions,
             Activity activity,
             com.parse.LogInCallback callback)

Logs in a user using the default activity code if single sign-on is enabled.

See Also:
  `ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)`

#### logIn

    public static void logIn(Activity activity,
             com.parse.LogInCallback callback)

See Also:
  `ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)`

#### finishAuthentication

    public static void finishAuthentication(int requestCode,
                            int resultCode,
                            Intent data)

Completes authentication after the Facebook app returns an activity result. IMPORTANT: This method must be invoked at the top of the calling activity's onActivityResult() function or Facebook authentication will not function properly!

If your calling activity does not currently implement onActivityResult(), you must implement it and include a call to this method if you intend to use the `ParseFacebookUtils.logIn(Activity, int, LogInCallback)` or `ParseFacebookUtils.link(ParseUser, Activity, int, SaveCallback)` methods in `ParseFacebookUtilities` . For more information, see http://developer.android.com/reference/android/app/ Activity.html#onActivityResult(int, int, android.content.Intent)

#### saveLatestSessionDataInBackground

    public static Task<Void> saveLatestSessionDataInBackground(com.parse.ParseUser user)

Saves the latest session data to the user. Call this after requesting new read or publish permissions for the user's Facebook session.

Parameters:
  `user` - The user whose session information should be updated.
Returns:
  A Task that is resolved when the session save is completed.

#### saveLatestSessionData

    public static void saveLatestSessionData(com.parse.ParseUser user,
                             com.parse.SaveCallback callback)

Saves the latest session data to the user. Call this after requesting new read or publish permissions for the user's Facebook session.

Parameters:
  `user` - The user whose session information should be updated.
  `callback` - Callback invoked when the session data has been saved.

#### saveLatestSessionData

    @Deprecated
    public static void saveLatestSessionData(com.parse.ParseUser user)

Deprecated. Please use `ParseFacebookUtils.saveLatestSessionDataInBackground(ParseUser)` instead.

#### shouldExtendAccessToken

    @Deprecated
    public static boolean shouldExtendAccessToken(com.parse.ParseUser user)

Deprecated. This is now handled automatically by the Facebook SDK.

#### extendAccessToken

    @Deprecated
    public static void extendAccessToken(com.parse.ParseUser user,
                                    Context context,
                                    com.parse.SaveCallback callback)

Deprecated. This is now handled automatically by the Facebook SDK.

#### extendAccessTokenIfNeeded

    @Deprecated
    public static boolean extendAccessTokenIfNeeded(com.parse.ParseUser user,
                                               Context context,
                                               com.parse.SaveCallback callback)

Deprecated. This is now handled automatically by the Facebook SDK.