Deprecated Plus.PeopleApi.load

Now that Plus.API deprecated in Google Play Services 9.4 , what is the right way to get Google Plus circles for an authenticated user in an Android app?

We now have an outdated download method plus Plus.PeopleApi.load users

The new documentation says:

If your app needs social information and more extensive profile data, check out the Android contact provider or cross-platform people API.

So, I have to go with the Android Contacts provider, which seems like a difficult alternative (because I need to filter contacts with cursors and also manage runtime permissions).

Any simple alternatives to the previous deprecated method to just get a list of G + circles for the user?

+6
source share
1 answer

The Google+ People API will eventually be completely deprecated in 2017 Q1, see deprecation notes below for details:

Android ad: https://developers.google.com/+/mobile/android/api-deprecation

REST endpoint declaration: https://developers.google.com/+/web/people/#retrieve-a-collection-of-people

So, you should consider the proposed alternatives and not create new functions based on G + Circle friends, since no data will be available to new users with the plus.login area .

If you don't want to request permissions at runtime, you can still get signed-in user contacts from the People REST API (note that this is something different from the G + People API). In addition, if you need user profile input other than the first / last / display name, email URL, and image profile (which is already provided by the login API), you should also use the same new People API.

In Android, when you need contact information ( In context, explaining to the user why you are requesting information about your contacts. DO NOT request the contact area in your first input activity )

 // Add dependencies (SDKs will be downloaded from mavenCentral) compile 'com.google.api-client:google-api-client:1.22.0' compile 'com.google.api-client:google-api-client-android:1.22.0' compile 'com.google.apis:google-api-services-people:v1-rev4-1.22.0' 

Then write the login code.

 // Make sure your GoogleSignInOptions request email & contacts scopes as shown below GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestScopes(new Scope(PeopleScopes.CONTACTS_READONLY))) .build(); // Follow official doc to sign-in. // https://developers.google.com/identity/sign-in/android/sign-in 

You can then use the new People Api to retrieve your contact list.

 /** Global instance of the HTTP transport. */ private static HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport(); /** Global instance of the JSON factory. */ private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); // On worker thread GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(MainActivity.this, PeopleScopes.CONTACTS_READONLY); credential.setSelectedAccount( new Account(googleSignInAccount.getEmail(), "com.google")); People service = new People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME /* whatever you like */) .build(); ListConnectionsResponse response = service.people().connections() .list("people/me") // request 20 contacts .setPageSize(20) .execute(); List<Person> connections = response.getConnections(); if (connections != null && connections.size() > 0) { for (Person person : connections) { List<Name> names = person.getNames(); if (names != null && names.size() > 0) { Log.i(TAG, "Name: " + person.getNames().get(0).getDisplayName()); } else { Log.i(TAG, "No names available for connection."); } List<Gender> genders = person.getGenders(); String ageRange = person.getAgeRange(); List<Birthday> birthdays = person.getBirthdays(); ... } } 
+4
source

All Articles