Hello all actually i need to sign in people from google+ through my app now i read documentation on google where it isstated that
To allow users to sign
Because you have said your current app works well with Google Sign-in already, so in order to get Google+ profile information such as Gender, Birthday..., first of all, make sure you have created Google+ profile for your Google account. Then you can update your app with the following codes. Please pay attention that I use .requestScopes(new Scope(Scopes.PLUS_LOGIN))
at GoogleSignInOptions
, not at mGoogleApiClient
.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestEmail()
.build();
and
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Plus.API)
.build();
Then
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
// G+
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (person != null){
Log.i(TAG, "--------------------------------");
Log.i(TAG, "Display Name: " + person.getDisplayName());
Log.i(TAG, "Gender: " + person.getGender());
Log.i(TAG, "AboutMe: " + person.getAboutMe());
Log.i(TAG, "Birthday: " + person.getBirthday());
Log.i(TAG, "Current Location: " + person.getCurrentLocation());
Log.i(TAG, "Language: " + person.getLanguage());
}
}
}
Inside build.gradle
file
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
P/S: if Google+ profile has been created but after the time you add Google account in your device, you need to delete that existing Google account from your device, then re-add. When you run your app again, the message asking you allow/deny to access Google+ will be displayed. And of course, you must click Allow.
Hope this helps and is clear for you!