从GoogleSignInAccount获取高质量的个人资料图片 [英] Get high quality profile picture from GoogleSignInAccount

查看:129
本文介绍了从GoogleSignInAccount获取高质量的个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中,为了通过 google帐户进行身份验证,我遵循了此官方教程

In my Android application in order to authenticate through the google account, I follow this official tutorial https://developers.google.com/identity/sign-in/android/people#retrieve_profile_information_for_a_signed-in_user and it works.

如此处所述,要检索个人资料图片,请使用"GoogleSignInAccount"类的" getPhotoUrl()"方法.示例:

As stated there, to retrieve the profile picture I use "getPhotoUrl()" method of "GoogleSignInAccount" class. Example:

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();

问题是我通过此URL获得的图像质量很差(尺寸较小).

The problem is that the image that I get through this URL is very poor quality (small size).

屏幕截图示例

如何解决此问题?

推荐答案

如果您的照片网址具有sz=50密钥(图像大小为50左右).然后将尺寸更换为最大.就像sz=240

If your photo url has sz=50 key (image size 50 or something). Then replace size to the highest. like sz=240

我不确定您的照片网址是否具有sz密钥,因为我使用了Person API(具有getUrl()sz密钥)来获取用户详细信息,而现在该信息已被弃用.

I am not sure your photo url has sz key because I used Person API which has sz key for getUrl() to get user details which is now deprecated.

更新:

UPDATED: Person.Image - Official doc which says how to get different dimens of profile avatar

此人的个人资料照片的网址.要调整图像大小并将其裁剪为正方形,请附加查询字符串?sz = x,其中x是每边的尺寸(以像素为单位)

The URL of the person's profile photo. To resize the image and crop it to a square, append the query string ?sz=x, where x is the dimension in pixels of each side


但是,正如@ stackpic91所说,新API GoogleSignInAccount.getPhotoUrl()已将 S96-c 的值更改为最高值以获取大图像 S240-c


However as @stackpic91 said new API GoogleSignInAccount.getPhotoUrl() has S96-c change its value to the highest to get large image S240-c

这篇关于从GoogleSignInAccount获取高质量的个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆