Skip to content Skip to sidebar Skip to footer

Get User Name From Google Plus In Android

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 v

Solution 1:

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!

Solution 2:

You have to add this line:

Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);

Like this:

publicvoidonConnected(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();
       .........
    }
}

Solution 3:

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();

Solution 4:

Check that you generated both of debug and production Client ID by SHA1 keystores. It display in APIs & Auth -> Credentials tab of your project.

Setting up OAuth 2.0 for Android documentation says:

In a terminal, run the Keytool utility to get the SHA1 fingerprint for your digitally signed .apk file's public certificate.

...example for debug-keystore...

Important: When you prepare to release your app to your users, follow these steps again and create a new OAuth 2.0 client ID for your production app. For production apps, use your own private key to sign the production app's .apk file.

Solution 5:

I tried a lot of approaches but I was still facing the same issue. Finally, in app build.gradle file, I found that my applicationId was not same as the package name in Credentials. I fixed that and everything worked like a charm.

Thus, make sure:

  • applicationId in build.gradle
  • package name in AndroidManifest.xml
  • package name in Credentials

are all same.

Hope this helps someone.

Post a Comment for "Get User Name From Google Plus In Android"