0

那麼,我可以訪問當前FirebaseUser對象爲FirebaseAuth.getInstance().getCurrentUser(),然後我可以撥打getPhotoUrl()getDisplayName()方法。 問題在於用戶UUID,如何訪問另一個用戶的對象並調用這些方法?如何訪問其他FirebaseUser的屬性?

PS:在Android

+0

這將被稱爲安全漏洞......懷疑你會做到這一點。 – theblindprophet

+0

@theblindprophet所以我應該讓自己的JSON樹來保持這些信息並在用戶之間正確共享吧?這不是冗餘,以保持相同的信息兩次? – guness

+1

如果您希望其他用戶有權訪問信息,那麼請使用該信息創建您自己的子樹。 – theblindprophet

回答

0

常見的方式做,這是存儲有關的火力地堡數據庫中的用戶可共享信息。

firebase.com上的文檔有一個很好的例子。請參閱https://www.firebase.com/docs/android/guide/user-auth.html#section-storing儘管您需要稍微修改代碼,但該方法與新的Firebase更改仍然相同。

我會添加一條說明,我們需要將這個示例添加到新的Firebase文檔中。

0

FirebaseUser具有一組固定的基本屬性 - 唯一ID,主電子郵件地址,名稱和照片URL,存儲在單獨項目的用戶數據庫中;這些屬性可以由用戶更新。您無法直接將其他屬性添加到FirebaseUser對象;相反,您可以將其他屬性存儲在您的Firebase實時數據庫中。

FirebaseAuth mAuth = FirebaseAuth.getInstance(); 

mAuth.createUserWithEmailAndPassword("[email protected]", "my pass") 
    .continueWithTask(new Continuation<AuthResult, Task<Void>> { 
     @Override 
     public Task<Void> then(Task<AuthResult> task) { 
      if (task.isSuccessful()) { 
       FirebaseUser user = task.getResult().getUser(); 
       DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReference(); 
       return firebaseRef.child("users").child(user.getUid()).child("phone").setValue("650-253-0000"); 
      } else { 
       // User creation didn't succeed. Look at the task exception 
       // to figure out what went wrong 
       Log.w(TAG, "signInWithEmail", task.getException()); 
      } 
     } 
    }); 
相關問題