How to use Facebook's new LoginManager.createLogInActivityResultContract properly?

Viewed 242

Facebook added a new API (LoginManager.createLogInActivityResultContract) for handling login using the ActivityResultContract APIs in SDK version 13.2.0 (https://github.com/facebook/facebook-android-sdk/blob/main/CHANGELOG.md#1320)

So far I've been able to work out how to launch the activity with the requested scopes thanks to the documentation here: https://github.com/facebook/facebook-android-sdk/commit/9cc564990b9512d767201b74136d71a5ea13fc64

But what I'm not able to do is understand how to access the result of the login activity.

For example: In this block:

val launcher = registerForActivityResult(
  loginManager.createLogInActivityResultContract(callbackManager)) { activityResult ->
    // activityResult is of type CallbackManager.ActivityResultParameters, how do I know if the login was successful? Or a failure occurred? Or the user canceled?
  }

The best I've been able to find is that you can get the CallbackManager.ActivityResultParameters intent value, and then look at the extras via the com.facebook.LoginFragment:Result key and the value returned is of type LoginClient.Result but that is marked as restricted (via @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) ) so I'm not sure that is... correct.

It works, and I can suppress the associated lint warnings that come from this, but having to:

  1. Use a hard coded string rather than a value from the FB sdk to access the intent extra bundle value
  2. Ignore a lint warning talking about how a restricted API/class is being used

to get this to work seems incomplete/wrong.

Am I missing anything here? Or is this still incomplete end to end?

0 Answers
Related