2017-06-17 25 views
0

投稿方法firebaseAuthで認証された場合、Gmailアカウントからファイヤーベースへの姓名を投稿する方法?ユーザープロフィールを取得する方法。GmailアカウントからFirebaseへの投稿名

私は.. GIDGoogleUserオーバーfirebaseでユーザーを作成し、使用しています:

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) 
    } 
} 

答えて

0

私は考え出しました。

let authentication = user.authentication 

この後に追加:

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

とでより:

   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": "..." 

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!) 
     } 

    } 

また、多くの他の細部のを取得することができます0

0

フォームのドキュメントhere

GIDGoogleUserクラスGIDProfileDataの一種であるprofileという名前のプロパティを持っています。

GIDProfileData必要な情報があります。

ルックhere

関連する問題