Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google+ Login with Play Services 6.5.87 (GoogleApiClient) - Android

In Play Services 6.1.71 I was using:

mPlusClient = new PlusClient.Builder(this,this,this).setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").setScopes(Scopes.PLUS_LOGIN, Scopes.PROFILE).build();

But in Google Play Services 6.5.87, Google suggest to change PlusClient to GoogleApiClient.Builder instead. But I'm not able to get user info as before:

mPlusClient.getAccountName() 

or

mPlusClient.getCurrentPerson()

How can I retrieve the user info? I think Google documentation is out of date. Hope you can help me. Thank you.

like image 236
Brigadier Avatar asked Dec 14 '14 18:12

Brigadier


People also ask

What is GoogleApiClient?

You can use the GoogleApiClient ("Google API Client") object to access the Google APIs provided in the Google Play services library (such as Google Sign-In, Games, and Drive).

How do I communicate with Google Play Services?

To update Google Play Services on your Android device, head to the "Apps & Notifications" menu in your settings. Google Play Services let your Android apps connect to the internet and communicate with Google. Updating Google Play Services can fix app issues, and help your Android device run faster.


Video Answer


1 Answers

Use GoogleApiClient, not PlusClient. Sample:

mGoogleApiClient = new GoogleApiClient.Builder(mContext)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

To getAccountName() use Plus.AccountApi.getAccountName(mGoogleApiClient)

To getCurrentPerson() use Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)

like image 89
Yura Nalivayko Avatar answered Nov 15 '22 00:11

Yura Nalivayko