Android : How to get larger profile pic from Facebook using FirebaseAuth?

后端 未结 8 562
孤街浪徒
孤街浪徒 2021-01-30 14:25

I am using FirebaseAuth to login user through FB. Here is the code:

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
pr         


        
8条回答
  •  孤街浪徒
    2021-01-30 15:14

    If someone is looking for this but for Google account using FirebaseAuth. I have found a workaround for this. If you detail the picture URL:

    https://lh4.googleusercontent.com/../.../.../.../s96-c/photo.jpg

    The /s96-c/ specifies the image size (96x96 in this case)so you just need to replace that value with the desired size.

    String url= FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
    url = url.replace("/s96-c/","/s300-c/");
    

    You can analyze your photo URL to see if there is any other way to change its size.

    As I said in the begining, this only works for Google accounts. Check @Mathias Brandt 's answer to get a custom facebook profile picture size.

    EDIT 2020:

    Thanks to Andres SK and @alextouzel for pointing this out. Photo URLs format have changed and now you can pass URL params to get different sizes of the picture. Check https://developers.google.com/people/image-sizing.

提交回复
热议问题