I want to integrate google sign in to my app, when user first sign in I will create an account bind to this, so I need some profiles like gender, locale, etc. and I tried as
The Plus people stuff is deprecated, don't use it anymore. The way to do this is with the Google People API Enable this API in your project. If you don't, the exception thrown in Studio includes a link directly to your project to enable it (nice).
Include the following dependencies in your app's build.gradle:
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'
Do an authorized GoogleSignIn like normal. It doesn't need any Scopes or Api's other than the basic account ones e.g.
GoogleSignInOptions.DEFAULT_SIGN_IN
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
and requests for email and profile is all you need.
Now, once you have a successful signin result, you can get the account, including the email (could maybe do this with the id too).
final GoogleSignInAccount acct = googleSignInResult.getSignInAccount();
Now the new part: Create and execute an AsyncTask to call the Google People API after you get the acct email.
// get Cover Photo Asynchronously
new GetCoverPhotoAsyncTask().execute(Prefs.getPersonEmail());
Here is the AsyncTask:
// Retrieve and save the url to the users Cover photo if they have one
private class GetCoverPhotoAsyncTask extends AsyncTask {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
// Retrieved from the sigin result of an authorized GoogleSignIn
String personEmail;
@Override
protected Void doInBackground(String... params) {
personEmail = params[0];
Person userProfile = null;
Collection scopes = new ArrayList<>(Collections.singletonList(Scopes.PROFILE));
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(SignInActivity.this, scopes);
credential.setSelectedAccount(new Account(personEmail, "com.google"));
People service = new People.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(getString(R.string.app_name)) // your app name
.build();
// Get info. on user
try {
userProfile = service.people().get("people/me").execute();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
// Get whatever you want
if (userProfile != null) {
List covers = userProfile.getCoverPhotos();
if (covers != null && covers.size() > 0) {
CoverPhoto cover = covers.get(0);
if (cover != null) {
// save url to cover photo here, load at will
//Prefs.setPersonCoverPhoto(cover.getUrl());
}
}
}
return null;
}
}
Here is the stuff that is available from the Person
If you paste the code into your project, make sure the imports get resolved correctly. There are overlapping Class Names with some of the older API's.