com.parse
Class ParseFacebookUtils

Object
  extended by com.parse.ParseFacebookUtils

public final class ParseFacebookUtils
extends Object

Provides a set of utilities for using Parse with Facebook.


Field Summary
protected static com.parse.FacebookAuthenticationProvider provider
           
 
Method Summary
static void extendAccessToken(ParseUser user, Context context, SaveCallback callback)
          Deprecated. This is now handled automatically by the Facebook SDK.
static boolean extendAccessTokenIfNeeded(ParseUser user, Context context, 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 com.facebook.android.Facebook getFacebook()
          Deprecated. Please use ParseFacebookUtils.getSession() and related Facebook SDK 3.0+ APIs instead.
static com.facebook.Session getSession()
           
protected static void initialize()
           
static void initialize(String appId)
          Initializes Facebook for use with Parse.
static boolean isLinked(ParseUser user)
           
static void link(ParseUser user, Activity activity)
          Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity) instead.
static void link(ParseUser user, Activity activity, int activityCode)
          Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity, int) instead.
static void link(ParseUser user, Activity activity, int activityCode, SaveCallback callback)
           
static void link(ParseUser user, Activity activity, SaveCallback callback)
           
static void link(ParseUser user, Collection<String> permissions, Activity activity)
          Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity) instead.
static void link(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(ParseUser user, Collection<String> permissions, Activity activity, int activityCode, 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(ParseUser user, Collection<String> permissions, Activity activity, SaveCallback callback)
          Links a user using the default activity code if single sign-on is enabled.
static void link(ParseUser user, String facebookId, String accessToken, Date expirationDate)
          Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, String, String, java.util.Date) instead.
static void link(ParseUser user, String facebookId, String accessToken, Date expirationDate, 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 bolts.Task<Void> linkInBackground(ParseUser user, Activity activity)
           
static bolts.Task<Void> linkInBackground(ParseUser user, Activity activity, int activityCode)
           
static bolts.Task<Void> linkInBackground(ParseUser user, Collection<String> permissions, Activity activity)
           
static bolts.Task<Void> linkInBackground(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 bolts.Task<Void> linkInBackground(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, LogInCallback callback)
           
static void logIn(Activity activity, LogInCallback callback)
           
static void logIn(Collection<String> permissions, Activity activity, int activityCode, LogInCallback callback)
          Logs in a ParseUser using Facebook for authentication.
static void logIn(Collection<String> permissions, Activity activity, 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, LogInCallback callback)
          Logs in a ParseUser using Facebook for authentication.
static bolts.Task<ParseUser> logInInBackground(Collection<String> permissions, Activity activity, int activityCode)
          Logs in a ParseUser using Facebook for authentication.
static bolts.Task<ParseUser> logInInBackground(String facebookId, String accessToken, Date expirationDate)
          Logs in a ParseUser using Facebook for authentication.
static void saveLatestSessionData(ParseUser user)
          Deprecated. Please use ParseFacebookUtils.saveLatestSessionDataInBackground(ParseUser) instead.
static void saveLatestSessionData(ParseUser user, SaveCallback callback)
          Saves the latest session data to the user.
static bolts.Task<Void> saveLatestSessionDataInBackground(ParseUser user)
          Saves the latest session data to the user.
static boolean shouldExtendAccessToken(ParseUser user)
          Deprecated. This is now handled automatically by the Facebook SDK.
static void unlink(ParseUser user)
          Unlinks a user from a Facebook account.
static bolts.Task<Void> unlinkInBackground(ParseUser user)
          Unlinks a user from a Facebook account in the background.
static void unlinkInBackground(ParseUser user, SaveCallback callback)
          Unlinks a user from a Facebook account in the background.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

provider

protected static com.parse.FacebookAuthenticationProvider provider
Method Detail

getFacebook

@Deprecated
public static com.facebook.android.Facebook getFacebook()
Deprecated. Please use ParseFacebookUtils.getSession() and related Facebook SDK 3.0+ APIs instead.


getSession

public static com.facebook.Session getSession()
Returns:
The active Facebook session associated with the logged in ParseUser, or null if there is none.

isLinked

public static boolean isLinked(ParseUser user)
Returns:
true if the user is linked to a Facebook account.

initialize

protected static void initialize()

initialize

public static void initialize(String appId)
Initializes Facebook for use with Parse. Here, you can provide the set of permissions that will be used when accessing Facebook, and toggle whether Facebook's single sign-on feature should be used when calling ParseFacebookUtils.logIn(Activity, int, LogInCallback) or ParseFacebookUtils.link(ParseUser, Activity, int, SaveCallback). You may invoke this method more than once if you need to change the appId.

If this method is not called explicitly before using ParseFacebookUtils then the value of com.facebook.sdk.ApplicationId from the manifest metadata will be used automatically.

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:
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(ParseUser user)
                   throws 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:
ParseException

unlinkInBackground

public static bolts.Task<Void> unlinkInBackground(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(ParseUser user,
                                      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 bolts.Task<Void> linkInBackground(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(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(ParseUser user,
                        String facebookId,
                        String accessToken,
                        Date expirationDate,
                        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 bolts.Task<Void> linkInBackground(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 bolts.Task<Void> linkInBackground(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 bolts.Task<Void> linkInBackground(ParseUser user,
                                                Activity activity,
                                                int activityCode)
See Also:
ParseFacebookUtils.linkInBackground(ParseUser, java.util.Collection, android.app.Activity, int)

linkInBackground

public static bolts.Task<Void> linkInBackground(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(ParseUser user,
                        Collection<String> permissions,
                        Activity activity,
                        int activityCode,
                        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(ParseUser user,
                        Collection<String> permissions,
                        Activity activity,
                        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(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(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(ParseUser user,
                        Activity activity,
                        int activityCode,
                        SaveCallback callback)
See Also:
ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)

link

public static void link(ParseUser user,
                        Activity activity,
                        SaveCallback callback)
See Also:
ParseFacebookUtils.link(ParseUser, Collection, Activity, int, SaveCallback)

link

@Deprecated
public static void link(ParseUser user,
                                   Activity activity,
                                   int activityCode)
Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity, int) instead.


link

@Deprecated
public static void link(ParseUser user,
                                   Activity activity)
Deprecated. Please use ParseFacebookUtils.linkInBackground(ParseUser, android.app.Activity) instead.


logInInBackground

public static bolts.Task<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,
                         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 bolts.Task<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,
                         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,
                         LogInCallback callback)
See Also:
ParseFacebookUtils.logIn(Collection, Activity, int, LogInCallback)

logIn

public static void logIn(Collection<String> permissions,
                         Activity activity,
                         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,
                         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 bolts.Task<Void> saveLatestSessionDataInBackground(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(ParseUser user,
                                         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(ParseUser user)
Deprecated. Please use ParseFacebookUtils.saveLatestSessionDataInBackground(ParseUser) instead.


shouldExtendAccessToken

@Deprecated
public static boolean shouldExtendAccessToken(ParseUser user)
Deprecated. This is now handled automatically by the Facebook SDK.


extendAccessToken

@Deprecated
public static void extendAccessToken(ParseUser user,
                                                Context context,
                                                SaveCallback callback)
Deprecated. This is now handled automatically by the Facebook SDK.


extendAccessTokenIfNeeded

@Deprecated
public static boolean extendAccessTokenIfNeeded(ParseUser user,
                                                           Context context,
                                                           SaveCallback callback)
Deprecated. This is now handled automatically by the Facebook SDK.