我在Android應用程序項目中僅使用電子郵件/密碼使用Firebase身份驗證。我試圖訪問已用于登錄應用程序的電子郵件帳戶的圖片。但是,當我嘗試以下這三種方法時,photoUrl為空,并且我正在使用自己的電子郵件帳戶進行測試,我知道該帳戶具有個人資料圖片。 // METHOD ONE Uri photoUrl = mFirebaseUser.getPhotoUrl(); if (photoUrl != null) { log.d("PhotoUrl",photoUrl.toString()); } // METHOD TWO UserInfo userInfo = mFirebaseUser.getProviderData().get(0); Uri photoUrl = (Uri) userInfo.getPhotoUrl(); if (photoUrl != null) { log.d("PhotoUrl",photoUrl.toString()); } // METHOD THREE for (UserInfo userInfo:mUser.getProviderData()) { Uri photoUrl = userInfo1.getPhotoUrl(); if (photoUrl != null){ break; } } if (photoUrl != null) { log.d("PhotoUrl",photoUrl.toString()); }我能夠像這樣輕松獲取電子郵件帳戶的名稱 String name = mFirebaseUser.getDisplayName();
2 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
由于您僅在 FirebaseAuth 中使用電子郵件登錄,因此當您嘗試檢索用戶的照片網址時會出現問題,因為默認情況下用戶沒有照片網址。因此,您可以做的是要求用戶設置照片并使用FirebaseAuth保存網址(以便以后可以檢索)。您可以使用下面的代碼為用戶保存照片 URL。
UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
.setDisplayName("set new display name")
.setPhotoUri(uri)
.build();
FirebaseAuth.getInstance().getCurrentUser().updateProfile(userProfileChangeRequest);
設置照片網址后。嘗試獲取照片網址
FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl();
希望這有幫助!

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
試試這個
private FirebaseAuth mAuth; private FirebaseUser mCurrentUser;
初始化它
mAuth = FirebaseAuth.getInstance(); mCurrentUser = mAuth.getCurrentUser();
在圖像視圖中使用畢加索加載照片網址
Picasso.get().load(mCurrentUser.getPhotoUrl()) .into(imageView);
添加回答
舉報
0/150
提交
取消