Class ParseFacebookUtils


  • public final class ParseFacebookUtils
    extends java.lang.Object
    Provides a set of utilities for using Parse with Facebook.

    Note: ParseFacebookUtils requires Facebook Android SDK v4.x.x

    To use ParseFacebookUtils, you'll need to set up the Facebook SDK:

    Add the Facebook SDK: compile 'com.facebook.android:facebook-android-sdk:4.x.x'

    Add the following to the <application> node in your AndroidManifest.xml:

     <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id"/>
     

    Create facebook_app_id in your strings.xml with your Facebook App ID

    Then you can use ParseFacebookUtils:

    Initialize ParseFacebookUtils in your android.app.Application#onCreate:

     public class MyApplication extends Application {
       public void onCreate() {
         Parse.initialize(this);
         ...
         ParseFacebookUtils.initialize(this);
       }
     }
     

    Add ParseFacebookUtils#onActivityResult(int, int, android.content.Intent) to your android.app.Activity#onActivityResult(int, int, android.content.Intent):

     public class MyActivity extends Activity {
       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
       }
     }
     

    Lastly, log in with ParseFacebookUtils#logInWithReadPermissionsInBackground(android.app.Activity, java.util.Collection)

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void initialize​(Context context)
      Initializes ParseFacebookUtils and com.facebook.FacebookSdk.
      static void initialize​(Context context, int callbackRequestCodeOffset)
      Initializes ParseFacebookUtils and com.facebook.FacebookSdk.
      static boolean isLinked​(ParseUser user)  
      static <any> linkInBackground​(ParseUser user, AccessToken accessToken)
      Link an existing Parse user with a Facebook account using authorization credentials that have already been obtained.
      static <any> linkInBackground​(ParseUser user, AccessToken accessToken, SaveCallback callback)
      Link an existing Parse user with a Facebook account using authorization credentials that have already been obtained.
      static <any> linkWithPublishPermissionsInBackground​(ParseUser user, Activity activity, java.util.Collection<java.lang.String> permissions)
      Link an existing Parse user to Facebook with the requested publish permissions.
      static <any> linkWithPublishPermissionsInBackground​(ParseUser user, Activity activity, java.util.Collection<java.lang.String> permissions, SaveCallback callback)
      Link an existing Parse user to Facebook with the requested publish permissions.
      static <any> linkWithPublishPermissionsInBackground​(ParseUser user, Fragment fragment, java.util.Collection<java.lang.String> permissions)
      Link an existing Parse user to Facebook with the requested publish permissions.
      static <any> linkWithPublishPermissionsInBackground​(ParseUser user, Fragment fragment, java.util.Collection<java.lang.String> permissions, SaveCallback callback)
      Link an existing Parse user to Facebook with the requested publish permissions.
      static <any> linkWithReadPermissionsInBackground​(ParseUser user, Activity activity, java.util.Collection<java.lang.String> permissions)
      Link an existing Parse user to Facebook with the requested read permissions.
      static <any> linkWithReadPermissionsInBackground​(ParseUser user, Activity activity, java.util.Collection<java.lang.String> permissions, SaveCallback callback)
      Link an existing Parse user to Facebook with the requested read permissions.
      static <any> linkWithReadPermissionsInBackground​(ParseUser user, Fragment fragment, java.util.Collection<java.lang.String> permissions)
      Link an existing Parse user to Facebook with the requested read permissions.
      static <any> linkWithReadPermissionsInBackground​(ParseUser user, Fragment fragment, java.util.Collection<java.lang.String> permissions, SaveCallback callback)
      Link an existing Parse user to Facebook with the requested read permissions.
      static <any> logInInBackground​(AccessToken accessToken)
      Log in using a Facebook account using authorization credentials that have already been obtained.
      static <any> logInInBackground​(AccessToken accessToken, LogInCallback callback)
      Log in using a Facebook account using authorization credentials that have already been obtained.
      static <any> logInWithPublishPermissionsInBackground​(Activity activity, java.util.Collection<java.lang.String> permissions)
      Log in using Facebook login with the requested publish permissions.
      static <any> logInWithPublishPermissionsInBackground​(Activity activity, java.util.Collection<java.lang.String> permissions, LogInCallback callback)
      Log in using Facebook login with the requested publish permissions.
      static <any> logInWithPublishPermissionsInBackground​(Fragment fragment, java.util.Collection<java.lang.String> permissions)
      Log in using Facebook login with the requested publish permissions.
      static <any> logInWithPublishPermissionsInBackground​(Fragment fragment, java.util.Collection<java.lang.String> permissions, LogInCallback callback)
      Log in using Facebook login with the requested publish permissions.
      static <any> logInWithReadPermissionsInBackground​(Activity activity, java.util.Collection<java.lang.String> permissions)
      Log in using Facebook login with the requested read permissions.
      static <any> logInWithReadPermissionsInBackground​(Activity activity, java.util.Collection<java.lang.String> permissions, LogInCallback callback)
      Log in using Facebook login with the requested read permissions.
      static <any> logInWithReadPermissionsInBackground​(Fragment fragment, java.util.Collection<java.lang.String> permissions)
      Log in using Facebook login with the requested read permissions.
      static <any> logInWithReadPermissionsInBackground​(Fragment fragment, java.util.Collection<java.lang.String> permissions, LogInCallback callback)
      Log in using Facebook login with the requested read permissions.
      static boolean onActivityResult​(int requestCode, int resultCode, Intent data)
      The method that should be called from the Activity's or Fragment's onActivityResult method.
      static <any> unlinkInBackground​(ParseUser user)
      Unlink a user from a Facebook account.
      static <any> unlinkInBackground​(ParseUser user, SaveCallback callback)
      Unlink a user from a Facebook account.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isLinked

        public static boolean isLinked​(ParseUser user)
        Parameters:
        user - A ParseUser object.
        Returns:
        true if the user is linked to a Facebook account.
      • initialize

        public static void initialize​(Context context)
        Initializes ParseFacebookUtils and com.facebook.FacebookSdk.

        This should be called in your android.app.Application#onCreate().

        Parameters:
        context - The application context
      • initialize

        public static void initialize​(Context context,
                                      int callbackRequestCodeOffset)
        Initializes ParseFacebookUtils and com.facebook.FacebookSdk.

        This should be called in your android.app.Application#onCreate().

        Parameters:
        context - The application context
        callbackRequestCodeOffset - The request code offset that Facebook activities will be called with. Please do not use the range between the value you set and another 100 entries after it in your other requests.
      • onActivityResult

        public static boolean onActivityResult​(int requestCode,
                                               int resultCode,
                                               Intent data)
        The method that should be called from the Activity's or Fragment's onActivityResult method.
        Parameters:
        requestCode - The request code that's received by the Activity or Fragment.
        resultCode - The result code that's received by the Activity or Fragment.
        data - The result data that's received by the Activity or Fragment.
        Returns:
        true if the result could be handled.
      • logInInBackground

        public static <any> logInInBackground​(AccessToken accessToken)
        Log in using a Facebook account using authorization credentials that have already been obtained.
        Parameters:
        accessToken - Authorization credentials of a Facebook user.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInInBackground

        public static <any> logInInBackground​(AccessToken accessToken,
                                              LogInCallback callback)
        Log in using a Facebook account using authorization credentials that have already been obtained.
        Parameters:
        accessToken - Authorization credentials of a Facebook user.
        callback - A callback that will be executed when logging in is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithReadPermissionsInBackground

        public static <any> logInWithReadPermissionsInBackground​(Activity activity,
                                                                 java.util.Collection<java.lang.String> permissions)
        Log in using Facebook login with the requested read permissions.
        Parameters:
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithReadPermissionsInBackground

        public static <any> logInWithReadPermissionsInBackground​(Activity activity,
                                                                 java.util.Collection<java.lang.String> permissions,
                                                                 LogInCallback callback)
        Log in using Facebook login with the requested read permissions.
        Parameters:
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when logging in is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithPublishPermissionsInBackground

        public static <any> logInWithPublishPermissionsInBackground​(Activity activity,
                                                                    java.util.Collection<java.lang.String> permissions)
        Log in using Facebook login with the requested publish permissions.
        Parameters:
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithPublishPermissionsInBackground

        public static <any> logInWithPublishPermissionsInBackground​(Activity activity,
                                                                    java.util.Collection<java.lang.String> permissions,
                                                                    LogInCallback callback)
        Log in using Facebook login with the requested publish permissions.
        Parameters:
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when logging in is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithReadPermissionsInBackground

        public static <any> logInWithReadPermissionsInBackground​(Fragment fragment,
                                                                 java.util.Collection<java.lang.String> permissions)
        Log in using Facebook login with the requested read permissions.
        Parameters:
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithReadPermissionsInBackground

        public static <any> logInWithReadPermissionsInBackground​(Fragment fragment,
                                                                 java.util.Collection<java.lang.String> permissions,
                                                                 LogInCallback callback)
        Log in using Facebook login with the requested read permissions.
        Parameters:
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when logging in is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithPublishPermissionsInBackground

        public static <any> logInWithPublishPermissionsInBackground​(Fragment fragment,
                                                                    java.util.Collection<java.lang.String> permissions)
        Log in using Facebook login with the requested publish permissions.
        Parameters:
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when logging in is complete.
      • logInWithPublishPermissionsInBackground

        public static <any> logInWithPublishPermissionsInBackground​(Fragment fragment,
                                                                    java.util.Collection<java.lang.String> permissions,
                                                                    LogInCallback callback)
        Log in using Facebook login with the requested publish permissions.
        Parameters:
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when logging in is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • linkInBackground

        public static <any> linkInBackground​(ParseUser user,
                                             AccessToken accessToken)
        Link an existing Parse user with a Facebook account using authorization credentials that have already been obtained.
        Parameters:
        user - The Parse user to link with.
        accessToken - Authorization credentials of a Facebook user.
        Returns:
        A task that will be resolved when linking is complete.
      • linkInBackground

        public static <any> linkInBackground​(ParseUser user,
                                             AccessToken accessToken,
                                             SaveCallback callback)
        Link an existing Parse user with a Facebook account using authorization credentials that have already been obtained.
        Parameters:
        user - The Parse user to link with.
        accessToken - Authorization credentials of a Facebook user.
        callback - A callback that will be executed when linking is complete.
        Returns:
        A task that will be resolved when logging in is complete.
      • linkWithReadPermissionsInBackground

        public static <any> linkWithReadPermissionsInBackground​(ParseUser user,
                                                                Activity activity,
                                                                java.util.Collection<java.lang.String> permissions)
        Link an existing Parse user to Facebook with the requested read permissions.
        Parameters:
        user - The Parse user to link with.
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithReadPermissionsInBackground

        public static <any> linkWithReadPermissionsInBackground​(ParseUser user,
                                                                Activity activity,
                                                                java.util.Collection<java.lang.String> permissions,
                                                                SaveCallback callback)
        Link an existing Parse user to Facebook with the requested read permissions.
        Parameters:
        user - The Parse user to link with.
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when linking is complete.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithPublishPermissionsInBackground

        public static <any> linkWithPublishPermissionsInBackground​(ParseUser user,
                                                                   Activity activity,
                                                                   java.util.Collection<java.lang.String> permissions)
        Link an existing Parse user to Facebook with the requested publish permissions.
        Parameters:
        user - The Parse user to link with.
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithPublishPermissionsInBackground

        public static <any> linkWithPublishPermissionsInBackground​(ParseUser user,
                                                                   Activity activity,
                                                                   java.util.Collection<java.lang.String> permissions,
                                                                   SaveCallback callback)
        Link an existing Parse user to Facebook with the requested publish permissions.
        Parameters:
        user - The Parse user to link with.
        activity - The activity which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when linking is complete.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithReadPermissionsInBackground

        public static <any> linkWithReadPermissionsInBackground​(ParseUser user,
                                                                Fragment fragment,
                                                                java.util.Collection<java.lang.String> permissions)
        Link an existing Parse user to Facebook with the requested read permissions.
        Parameters:
        user - The Parse user to link with.
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithReadPermissionsInBackground

        public static <any> linkWithReadPermissionsInBackground​(ParseUser user,
                                                                Fragment fragment,
                                                                java.util.Collection<java.lang.String> permissions,
                                                                SaveCallback callback)
        Link an existing Parse user to Facebook with the requested read permissions.
        Parameters:
        user - The Parse user to link with.
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when linking is complete.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithPublishPermissionsInBackground

        public static <any> linkWithPublishPermissionsInBackground​(ParseUser user,
                                                                   Fragment fragment,
                                                                   java.util.Collection<java.lang.String> permissions)
        Link an existing Parse user to Facebook with the requested publish permissions.
        Parameters:
        user - The Parse user to link with.
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        Returns:
        A task that will be resolved when linking is complete.
      • linkWithPublishPermissionsInBackground

        public static <any> linkWithPublishPermissionsInBackground​(ParseUser user,
                                                                   Fragment fragment,
                                                                   java.util.Collection<java.lang.String> permissions,
                                                                   SaveCallback callback)
        Link an existing Parse user to Facebook with the requested publish permissions.
        Parameters:
        user - The Parse user to link with.
        fragment - The fragment which is starting the login process.
        permissions - The requested permissions.
        callback - A callback that will be executed when linking is complete.
        Returns:
        A task that will be resolved when linking is complete.
      • unlinkInBackground

        public static <any> unlinkInBackground​(ParseUser user)
        Unlink a user from a Facebook account. This will save the user's data.
        Parameters:
        user - The user to unlink.
        Returns:
        A task that will be resolved when unlinking has completed.
      • unlinkInBackground

        public static <any> unlinkInBackground​(ParseUser user,
                                               SaveCallback callback)
        Unlink a user from a Facebook account. This will save the user's data.
        Parameters:
        user - The user to unlink.
        callback - A callback that will be executed when unlinking is complete.
        Returns:
        A task that will be resolved when linking is complete.