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

后端 未结 8 560
孤街浪徒
孤街浪徒 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:15

    Note: From Graph API v8.0 you must provide the access token for every UserID request you do.

    Hitting the graph API:

    https://graph.facebook.com//picture?height=1000&access_token=
    

    With firebase:

    FirebaseUser user = mAuth.getCurrentUser();
    String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" +
      loginResult.getAccessToken().getToken();
    

    You get the token from registerCallback just like this

           LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                FirebaseUser user = mAuth.getCurrentUser();
                String photoUrl = user.getPhotoUrl() + "/picture?height=1000&access_token=" + loginResult.getAccessToken().getToken();
            }
    
            @Override
            public void onCancel() {
                Log.d("Fb on Login", "facebook:onCancel");
            }
    
            @Override
            public void onError(FacebookException error) {
                Log.e("Fb on Login", "facebook:onError", error);
            }
        });
    

    This is what documentation says:

    Beginning October 24, 2020, an access token will be required for all UID-based queries. If you query a UID and thus must include a token:

    • use a User access token for Facebook Login authenticated requests
    • use a Page access token for page-scoped requests
    • use an App access token for server-side requests
    • use a Client access token for mobile or web client-side requests

    We recommend that you only use a Client token if you are unable to use one of the other token types.

提交回复
热议问题