I have integrated Google plus with my android app. Everything is working fine, i am also connected to Google plus but I am not able to get the name of current user logged.
public void onConnected(Bundle connectionHint) {
String personName="Unknown";
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
personName = currentPerson.getDisplayName();
}
}
Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)
this method always return null.
Any help will appreciated. Thanks.
For me the cause of this call returning null was that the Google+ API Was not enabled for my application. Navigate to https://console.developers.google.com, select your project and enable the Google+ API to get it working!
You have to add this line:
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
Like this:
public void onConnected(Bundle connectionHint) {
/* This Line is the key */
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
String personName="Unknown";
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
personName = currentPerson.getDisplayName();
.........
}
}
In my case the null returned because I have added that line:
addScope(new Scope(Scopes.EMAIL))
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
//.addScope(new Scope(Scopes.EMAIL))
.build();
================= UPDATE ======================== Scopes should be set as below:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With