-->

Store Facebook Credential in Android for Google Sm

2019-02-22 00:44发布

问题:

Store Facebook Credential in Google Smart Lock Password

I was able to store basic username/password credentials in Smart Lock Password. There is plenty of documentation and examples for Google credentials:

GoogleSignInAccount gsa = signInResult.getSignInAccount();
Credential credential = new Credential.Builder(gsa.getEmail())
        .setAccountType(IdentityProviders.GOOGLE)
        .setName(gsa.getDisplayName())
        .setProfilePictureUri(gsa.getPhotoUrl())
        .build();

But so far, I was unable to store a Facebook credential. It should be something similar. But what exactly? Or is it something completely different or not supported?

Credential credential = new Credential.Builder(<what goes here?!>)
        .setAccountType(IdentityProviders.FACEBOOK)
        .setName(<and here?>)
        .setProfilePictureUri(<is this necessary?>)
        .build();

回答1:

I was able to get what I believe to be a working version of Smart Lock saving Facebook login credentials.

My app uses the FB API to login. From there I send a token to my server which in turn sends back the users email and username. I store that information like so:

    Credential credential = new Credential.Builder(user.getEmail())
       .setAccountType(IdentityProviders.FACEBOOK)
       .setName(user.getName())
       .build();

I'm not completely familiar with the Facebook API, but I think you could get the email and username from the Facebook SDK.

After using this to save the users FB credentials I am able to view them on passwords.google.com. The password shows as "With Facebook".