I am using Firebase Authentication for my Android app. Users have the ability to login with multiple providers (Google, Facebook, Twitter).
After a successful login, is there a way to get the user gender/birth date from these providers using the Firebase api?
4
Answers
No, you can’t get these data directly. But you can use the id of the user and get these data from various providers. Please check before what are the data that are available in the public API for each of these providers for instance google just deprecated few methods from the peopleApi.
Anyways here is what i do for facebook
And do the following inside the onClick of the FB login button
Unfortunately, Firebase doesn’t have any built-in functionality to get the user’s gender/birthdate upon successful login. You would have to retrieve these data from each of the providers yourself.
Here is how you might get the user’s gender from Google using Google People API
You can find more information on Accessing Google APIs
For Facebook :
To get facebook accessToken from firebase is very simple. I was using firebase auth UI. After authentication with facebook you will get basic information from firebase user object like display name, email,provider details. But if you want more information like gender, birthday facebook Graph API is the solution. Once user authenticated with the facebook you can get access token like this.
AccessToken.getCurrentAccessToken()
But sometimes it will give you NULL value instead of valid access token. Make sure that you have initialized facebook SDK before that.
}
After initialization use graphAPI
Happy Coding 🙂
Instead of using Googles People API classes to access their REST service I find it much simpler to just access the service directly.
Also saves 1.5 MB of APK size.
Output is easily parsable as JSON: