Android Firebase Auth - 获取用户的照片 [英] Android Firebase Auth - Get User's Photo
问题描述
如何检索用户的照片,分辨率合适,可在移动应用中使用?我查看了指南和 api 文档,推荐的方法似乎是使用 FirebaseUser#getPhotoUrl().但是,这会返回分辨率为 50x50 像素的照片的 URL,该值太低而无用.客户端有没有办法请求用户的高分辨率照片?我分别测试了 Facebook Login 和 Google Sign-in 的 sdk,在这两种情况下,照片的分辨率都高于 Firebase Auth 返回的分辨率.为什么 Firebase Auth 会更改原始分辨率,我该如何强制它不这样做?谢谢.
How can I retrieve a photo of the user with decent resolution that can be used from a mobile app? I looked at the guides and the api docs and the recommended way seemed to be to use FirebaseUser#getPhotoUrl(). This however gives back a url to a photo with resolution 50x50 px, which is too low to be useful. Is there a way for the client to request a higher res photo of the user? I've tested the sdks of Facebook Login and Google Sign-in separately, and in both cases the resolutions of the photos are higher than what Firebase Auth gives back. Why does Firebase Auth change the original resolutions and how can I force it not to do that? Thanks.
推荐答案
您可以拥有更好分辨率的个人资料图片,直接编辑两个提供商(Google 和 Facebook)的 URL:
You can have better resolution profile pics, directly editing the URL for both providers (Google and Facebook):
这是一个 javascript 示例代码,但您应该能够轻松转换为 Java:
Here is a javascript sample code but, you should be able to easily translate to Java:
getHigherResProviderPhotoUrl = ({ photoURL, providerId }: any): ?string => {
//workaround to get higer res profile picture
let result = photoURL;
if (providerId.includes('google')) {
result = photoURL.replace('s96-c', 's400-c');
} else if (providerId.includes('facebook')) {
result = `${photoURL}?type=large`;
}
return result;
};
基本上,根据提供商的不同,您只需要:
- 对于谷歌,将个人资料图片网址中的
s96-c
替换为s400-c
- 对于 facebook,只需在 url 末尾附加
?type=large
例如谷歌:
变成
对于 Facebook:
变成
这篇关于Android Firebase Auth - 获取用户的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!