Hi, I am trying to get my email from facebook since I play on iOS sdk in facebook using swift. The iOS platform is 10, fast 3, and Xcode 8. I have been following online tutorials, but I am having trouble getting email.
below is my code:
if FBSDKAccessToken.current() == nil { print("I got token") let fbButton = FBSDKLoginButton() fbButton.readPermissions = ["public_profile", "email", "user_friends"] view.addSubview(fbButton) fbButton.center = view.center fbButton.delegate = self self.fetchprofile() } else { print("Dont have token") let loginView : FBSDKLoginButton = FBSDKLoginButton() self.view.addSubview(loginView) loginView.center = self.view.center loginView.readPermissions = ["public_profile", "email", "user_friends"] loginView.delegate = self } func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { if error != nil { print(error.localizedDescription) return } print("I'm in") fetchprofile() } func fetchprofile() { print("Getting profile") let parameters = ["fields": "email"] let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: parameters, httpMethod: "GET") graphRequest.start(completionHandler: {(connection, result, error) -> Void in if error != nil { print("Error retrieving details: \(error?.localizedDescription)") return } guard let result = result as? [String:[AnyObject]], let email = result["email"] else { return } print("Email: \(email)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") self.view.backgroundColor = UIColor.red }) }
and in my appdelegate.swift file:
I can log in and log out, but I cannot receive an email.
UPDATE Actually, when I actually send print (email), I can see it on the console as an optional operator. I'm having trouble displaying it without an extra record
source share