2016-05-23 9 views
7

Wie kann ich ein Foto des Benutzers mit anständiger Auflösung abrufen, die von einer mobilen App verwendet werden kann? Ich schaute auf die Guides und die Api Docs und der empfohlene Weg schien FirebaseUser#getPhotoUrl() zu verwenden. Dies gibt jedoch eine URL an ein Foto mit der Auflösung 50x50 px zurück, die zu niedrig ist, um nützlich zu sein. Gibt es eine Möglichkeit für den Kunden, ein höheres Foto des Benutzers anzufordern? Ich habe die sdks von Facebook Login und Google-Anmeldung separat getestet, und in beiden Fällen sind die Auflösungen der Fotos höher als das, was Firebase Auth zurückgibt. Warum ändert Firebase Auth die ursprünglichen Auflösungen und wie kann ich dies erzwingen? Vielen Dank.Android Firebase Auth - Holen Sie sich das Foto des Benutzers

Antwort

1

Haben Sie versucht:

Uri xx = FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl(); 
+0

Ja, habe ich. Das gibt Ihnen ein 50x50 px Foto. – mobilekid

6

Innen onAuthStateChanged (@NonNull FirebaseAuth firebaseAuth)

versuchen, wenn Sie mit Facebook einloggen:

if (!user.getProviderData().isEmpty() && user.getProviderData().size() > 1) 
       String URL = "https://graph.facebook.com/" + user.getProviderData().get(1).getUid() + "/picture?type=large"; 
4

Facebook und Google PhotoURL:

 User myUserDetails = new User(); 
     myUserDetails.name = firebaseAuth.getCurrentUser().getDisplayName(); 
     myUserDetails.email = firebaseAuth.getCurrentUser().getEmail(); 

     String photoUrl = firebaseAuth.getCurrentUser().getPhotoUrl().toString(); 
     for (UserInfo profile : firebaseAuth.getCurrentUser().getProviderData()) { 
      System.out.println(profile.getProviderId()); 
      // check if the provider id matches "facebook.com" 
      if (profile.getProviderId().equals("facebook.com")) { 

       String facebookUserId = profile.getUid(); 

       myUserDetails.sigin_provider = profile.getProviderId(); 
       // construct the URL to the profile picture, with a custom height 
       // alternatively, use '?type=small|medium|large' instead of ?height= 

       photoUrl = "https://graph.facebook.com/" + facebookUserId + "/picture?height=500"; 

      } else if (profile.getProviderId().equals("google.com")) { 
       myUserDetails.sigin_provider = profile.getProviderId(); 
       ((HomeActivity) getActivity()).loadGoogleUserDetails(); 
      } 
     } 
     myUserDetails.profile_picture = photoUrl; 




private static final int RC_SIGN_IN = 8888;  

public void loadGoogleUserDetails() { 
     try { 
      // Configure sign-in to request the user's ID, email address, and basic profile. ID and 
      // basic profile are included in DEFAULT_SIGN_IN. 
      GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
        .requestEmail() 
        .build(); 

      // Build a GoogleApiClient with access to GoogleSignIn.API and the options above. 
      mGoogleApiClient = new GoogleApiClient.Builder(this) 
        .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() { 
         @Override 
         public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
          System.out.println("onConnectionFailed"); 
         } 
        }) 
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
        .build(); 

      Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
      startActivityForResult(signInIntent, RC_SIGN_IN); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 




@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     // Result returned from launching the Intent from 
     // GoogleSignInApi.getSignInIntent(...); 
     if (requestCode == RC_SIGN_IN) { 
      GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
      if (result.isSuccess()) { 
       GoogleSignInAccount acct = result.getSignInAccount(); 
       // Get account information 
       String PhotoUrl = acct.getPhotoUrl().toString(); 

      } 
     } 
    } 
+0

Ich habe dies für Facebook-Teil versucht und gelingen. Ich habe Google Teil noch nicht versucht. Vielen Dank – Dika

Verwandte Themen