[英]How to get profile picture of gmail account
I am trying to get profile picture associated with gmail account on android. 我想在android上获取与gmail帐户相关的个人资料图片。 I have used account picker intent to select/login to gmail (authentication) in my app.
我已经使用帐户选择器意图在我的应用程序中选择/登录gmail(身份验证)。 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 在启动oAuth后,我最终得到以下结果方法
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. 我不知道如何在上述案例中检索到个人资料图片的URL,任何帮助将不胜感激。
Quoting answer from - https://developers.google.com/identity/sign-in/android/people . 引用答案 - https://developers.google.com/identity/sign-in/android/people 。
Use the GoogleSignInResult.getSignInAccount method to request profile information for the currently signed in user. 使用GoogleSignInResult.getSignInAccount方法为当前登录的用户请求个人资料信息。
You can call the getSignInAccount method after the sign-in intent succeeds. 您可以在登录意图成功后调用getSignInAccount方法。
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.