I am trying to get profile picture associated with gmail account on android. I have used account picker intent to select/login to gmail (authentication) in my app. I have used following code
mCredential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName(settings.getString("PREF_ACCOUNT_NAME", null));
After initiating oAuth i end up with following method for result
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case REQUEST_ACCOUNT_PICKER:
if (resultCode == RESULT_OK && data != null &&
data.getExtras() != null) {
String accountName =
data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Log.e("ghfyg",""+accountName);
if (accountName != null) {
mCredential.setSelectedAccountName(accountName);
SharedPreferences settings =
AccountSync.this.getSharedPreferences("deep",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("PREF_ACCOUNT_NAME", accountName);
editor.apply();
}
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this,"Account unspecified.",Toast.LENGTH_SHORT).show();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
I am not sure how i can retrieve URL to profile picture in above case, any help will be appreciated.
Quoting answer from - https://developers.google.com/identity/sign-in/android/people.
Use the GoogleSignInResult.getSignInAccount method to request profile information for the currently signed in user.
You can call the getSignInAccount method after the sign-in intent succeeds.
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
String personName = acct.getDisplayName();
String personEmail = acct.getEmail();
String personId = acct.getId();
Uri personPhoto = acct.getPhotoUrl();
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