IOS Facebook SDK: login doesn't return email despite permissions granted

后端 未结 8 2077
[愿得一人]
[愿得一人] 2020-12-10 12:46

I\'m trying to get information through the facebook sdk but so far I\'m getting only the id and the name of the user, although I\'m sure there is an email available, as it i

8条回答
  •  抹茶落季
    2020-12-10 13:34

    Use these functions this will work for sure

    @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"]).start(completionHandler: { (connection, result, error) in
        if(error == nil){
        print("result")
        }
        })
        }
        }
    

    and connect the fbsignup(_sender: Any) function with your button

提交回复
热议问题