gpt4 book ai didi

ios - 将名字和姓氏从 Gmail 帐户发布到 Firebase

转载 作者:行者123 更新时间:2023-11-30 12:22:40 25 4
gpt4 key购买 nike

通过 firebaseAuth 完成身份验证后,如何将 Gmail 帐户中的名字和姓氏发布到 firebase。?如何获取用户个人资料?

我正在 firebase 中通过 GIDGoogleUser 创建用户..并使用:

let authentication = user.authentication

我在同一个类上发现了我可能可以使用的东西,但我需要建议这是正确的方法以及如何从中获取名字和姓氏..?

let profile = user.profile

我的AppDelegate.swift

import UIKit
import Firebase

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

FirebaseApp.configure()

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self

UIApplication.shared.statusBarStyle = .lightContent
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print(error.localizedDescription)
return
}
let authentication = user.authentication
let credential = GoogleAuthProvider.credential(withIDToken (authentication?.idToken)!,accessToken: (authentication?.accessToken)!)

Auth.auth().signIn(with: credential) { (user, error) in
if error != nil {
return
} else {
let registrationReq = FirebaseRegistrationLoginRequests()
registrationReq.checkIfCreateOrGetUser(user: user!)
}
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user:GIDGoogleUser!, withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
debugPrint(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
}

最佳答案

我明白了。

添加到之后

let authentication = user.authentication

这个:

let fullName = user.profile.name
let firstName = user.profile.givenName
let lastName = user.profile.familyName

并且比:

    Auth.auth().signIn(with: credential) { (user, error) in

debugPrint("fullName:", fullName!)
debugPrint("firstName:", firstName!)
debugPrint("lastName:", lastName!)

if error != nil {
return
} else {
let registrationReq = FirebaseRegistrationLoginRequests()
registrationReq.checkIfCreateOrGetUser(user: user!)
}

}

您还可以获得许多其他详细信息:

             Get the account information you want here from the dictionary
Possible values are
"id": "...",
"email": "...",
"verified_email": ...,
"name": "...",
"given_name": "...",
"family_name": "...",
"link": "https://plus.google.com/...",
"picture": "https://lh5.googleuserco...",
"gender": "...",
"locale": "..."

关于ios - 将名字和姓氏从 Gmail 帐户发布到 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com