2016-08-04 36 views
1

我將我的應用程序連接到Facebook和Google Firebase。我遵循所有步驟,每件事情都正常,但在Firebase Google中生成的數據庫是空的。我是否需要使用實時數據庫,然後以編程方式存儲FB用戶數據?或者當您登錄時,FB用戶信息會自動存儲在Firebase數據庫中。供參考: https://firebase.google.com/docs/auth/ios/facebook-login無法在facebook中存儲Facebook用戶數據firebase

-(void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error 
{ 

    if (error == nil) { 

     FIRAuthCredential *credential = [FIRFacebookAuthProvider 
             credentialWithAccessToken:[FBSDKAccessToken currentAccessToken] 
             .tokenString]; 

     [[FIRAuth auth] signInWithCredential:credential 
            completion:^(FIRUser *user, NSError *error) { 
             // ... 
            }]; 
    } else { 

     NSLog(@"%@", error.localizedDescription); 
    } 

} 
- (IBAction)FBLogin:(id)sender { 

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 

    [login 
    logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends",@"user_birthday",@"user_location"] 
    fromViewController:self 

    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
     if (error) { 
      NSLog(@"Process error"); 
     } else if (result.isCancelled) { 
      NSLog(@"Cancelled"); 
     } else { 
      NSLog(@"Logged in"); 
      [self performSegueWithIdentifier:@"GotoMainMenu" sender:self]; 
     } 
    }]; 
} 
+1

使用Firebase身份驗證進行登錄不會自動將有關用戶的信息添加到Firebase數據庫。如果你想存儲這樣的信息,你必須從你的代碼中自己做。 –

+0

謝謝@FrankvanPuffelen。 – WasimSafdar

回答

1

...對不起,我剛纔編輯這是我對你不使用JavaScript實現的。我會留下答案,因爲它可能仍然有幫助。

等到您獲得基於密碼的身份驗證。這就是真正的樂趣開始的地方! :-)

有關Facebook的事情是他們默認情況下不給你用戶的電子郵件。我相信你可以通過他們的開發者門戶請求訪問它。其他提供商提供電子郵件。

就存儲displayName,photoURL和/或email而言,您將它們存儲在Auth系統中,並且該系統將記住數據服務器端,...用於密碼帳戶。 oAuth賬戶在登錄時提取這些數據,所以它不會失效。

我有一個有效的Web auth樣板,會給你一個headstart。它在https://github.com/rhroyston/firebase-auth

以下是如何在一個通道中完成基於密碼的用戶。

function registerPasswordUser(email,displayName,password,photoURL){ 
    var user = null; 
    //NULLIFY EMPTY ARGUMENTS 
    for (var i = 0; i < arguments.length; i++) { 
     arguments[i] = arguments[i] ? arguments[i] : null; 
    } 
    auth.createUserWithEmailAndPassword(email, password) 
    .then(function() { 
     user = auth.currentUser; 
     user.sendEmailVerification(); 
    }) 
    .then(function() { 
     user.updateProfile({ 
     displayName: displayName, 
     photoURL: photoURL 
     }); 
    }) 
    .catch(function(error) { 
     console.log(error.message,7000); 
    }); 
    console.log('Validation link was sent to ' + email + '.'); 
    } 
相關問題