Используйте зависимость 'com.google.apis: google-api-services-people: v1-rev4-1.22.0' в Gradle, чтобы включить API пользователей.
егрировалGoogle Sign-In
в моем приложении. Я могу получить пользователяEmail
а такжеDisplayName
, Теперь я хочу получить пользователяBirthdate
а такжеGender
.
Я добавил все необходимоеrequests
& Scopes
вGoogleApiClient
которые все предоставляются API. вот код
// [START configure_signin]
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile() <- This
.requestScopes(
new Scope(Scopes.PLUS_ME), new Scope(Scopes.PROFILE) <- This
)
.build();
// [END configure_signin]
// [START build_client]
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
Log.d(TAG, "onConnectionFailed:" + connectionResult);
}
} /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addScope(new Scope(Scopes.PLUS_ME)) <- This
.addScope(new Scope(Scopes.PROFILE)) <- This
.build();
// [END build_client]
Вот предоставленные Области вGoogleSignInAccount
private void setupUserData(GoogleSignInAccount acct) {
if (acct != null) {
mPrefs.setName(acct.getDisplayName());
mPrefs.setEmail(acct.getEmail());
if (acct.getPhotoUrl() != null) {
mPrefs.setPicURL(acct.getPhotoUrl().toString());
}
Set<Scope> scopes = acct.getGrantedScopes(); <- This
for (Scope scope : scopes) {
Log.d(TAG, "setupUserData: " + scope.toString()); <- This
}
}
}
Вот журнал предоставленscopes
D/SplashActivity: setupUserData: GrantedScopes size 6
D/SplashActivity: setupUserData: https://www.googleapis.com/auth/plus.me
D/SplashActivity: setupUserData: https://www.googleapis.com/auth/userinfo.email
D/SplashActivity: setupUserData: https://www.googleapis.com/auth/userinfo.profile
D/SplashActivity: setupUserData: email
D/SplashActivity: setupUserData: profile
D/SplashActivity: setupUserData: openid
Вот зависимость моего мобильного сервиса Google
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.google.android.gms:play-services-plus:10.2.0'
Теперь я не знаю, как получить доступ кuser's profile information
.