0
我正在開發iOS應用程序,需要用戶通過連接其Facebook帳戶來創建帳戶。一個月前,當我通過自己的Facebook帳戶進行測試時,Firebase創建的用戶UID格式爲「臉書:(臉書應用程序ID)」。這是我想要的。Firebase不會創建Facebook帳戶使用Facebook應用程序的用戶UID用戶ID
但是,最近,無論何時用戶通過將他們的Facebook帳戶與我的應用連接來創建新的acconut,Firebase都會使用隨機字符串創建用戶UID。例如:「E9FaL87wRmOKfhen2S6yszhCwtx1」。這可能是因爲新的Firebase更新?我應該經歷遷移過程嗎?
這裏是我的帳戶創建代碼:
@IBAction func facebookAuthAction(sender: AnyObject) {
let facebookLogin = FBSDKLoginManager()
facebookLogin.logInWithReadPermissions(nil, fromViewController: nil, handler: {(facebookResult, facebookError) -> Void in
if facebookError != nil {
print("Facebook login failed. Error \(facebookError)")
} else if facebookResult.isCancelled {
print("Facebook login was cancelled.")
} else {
let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
FIREBASE_REF.authWithOAuthProvider("facebook", token: accessToken, withCompletionBlock: { error, authData in
if error != nil {
print("Login failed. \(error)")
} else {
print("Logged in! \(authData)")
NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid")
FIREBASE_REF.childByAppendingPath("users").observeEventType(.Value, withBlock: {snapshot in
if snapshot.hasChild(authData.uid) == false {
self.createNewFBUser(authData.uid)
}
})
self.performSegueWithIdentifier("loginSegue", sender: self)
}
})
}
})
}
func createNewFBUser(uid: String) {
var emailAddress:String = ""
var firstName:String = ""
var lastName:String = ""
var pictureURL:String = ""
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).startWithCompletionHandler {(connection, result, error) -> Void in
if error != nil {
print(error)
return
}
if let email = result["email"] as? String {
emailAddress = email
}
if let first_name = result["first_name"] as? String {
firstName = first_name
}
if let last_name = result["last_name"] as? String {
lastName = last_name
}
if let picture = result["picture"] as? NSDictionary, data = picture["data"] as? NSDictionary, url = data["url"] as? String {
pictureURL = url
}
let newUser = [
"provider": "facebook",
"firstName": firstName,
"lastName": lastName,
"email": emailAddress,
"picture": pictureURL
]
FIREBASE_REF.childByAppendingPath("users").childByAppendingPath(uid).setValue(newUser)
}
}
我認爲您應該轉移到Firebase的新版本,我認爲Google會盡快關閉「舊」Firebase –
* Firebaser * Firebase.com網站將在可預見的未來保持運營。 Firebase 2.x SDK仍將受支持。這就是說:我們希望我們的開發人員能夠選擇升級到新的Firebase控制檯和API。 –
@Dylan:您是否已將此項目升級到新的[Firebase控制檯](https://console.firebase.google.com)? –