Android Firebase Auth - Get User's Photo

后端 未结 4 1687
旧巷少年郎
旧巷少年郎 2020-12-05 19:47

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 b

4条回答
  •  醉酒成梦
    2020-12-05 20:14

    You can have better resolution profile pics, directly editing the URL for both providers (Google and Facebook):

    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;
      };
    

    Basically, depending on the provider, you just need to:

    • for google replace s96-c in the profile pic url with s400-c
    • for facebook just append ?type=large at the end of the url

    For example for google:

    low-res pic becomes high-res pic

    And for facebook:

    low-res pic becomes high-res pic

提交回复
热议问题