Get email and name Facebook SDK v4.4.0 Swift

前端 未结 10 2126
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 02:22

TL;TR: How do I get the email and name of a user that is logged in on my app using the facebook SDK 4.4

So far I have managed to get login working, now I can get the

10条回答
  •  遥遥无期
    2020-12-08 02:54

    you can use this code to get email ,name and profile picture of user

       @IBAction func fbsignup(_ sender: Any) {
        let fbloginManger: FBSDKLoginManager = FBSDKLoginManager()
        fbloginManger.logIn(withReadPermissions: ["email"], from:self) {(result, error) -> Void in
            if(error == nil){
                let fbLoginResult: FBSDKLoginManagerLoginResult  = result!
    
                if( result?.isCancelled)!{
                    return }
    
    
                if(fbLoginResult .grantedPermissions.contains("email")){
                    self.getFbId()
                }
            }  }
    
    }
    func getFbId(){
    if(FBSDKAccessToken.current() != nil){
    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,name , first_name, last_name , email,picture.type(large)"]).start(completionHandler: { (connection, result, error) in
        guard let Info = result as? [String: Any] else { return } 
    
                if let imageURL = ((Info["picture"] as? [String: Any])?["data"] as? [String: Any])?["url"] as? String {
            //Download image from imageURL
        }
    if(error == nil){
    print("result")
    }
    })
    }
    }
    

提交回复
热议问题