title: How to get user email address using FBSDK in swift iOS for iPhone?
body: <p>I'm a self-learning fresher developing iPhone app using swift. I'm designing a login page for Facebook authentication using FBSDK. I have successfully implemented the login button that logs in and logs out. It returns the username and id, but it fails to graph user email id and shows a code 2500 error. Also I can't login with a new user. It automatically logs in with a same user.</p>
  
  <p>Here is the error:</p>
  
  <pre><code>UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
      body =     {
          error =         {
              code = 2500;
              "fbtrace_id" = BimF4Nuqx0v;
              message = "An active access token must be used to query information about the current user.";
              type = OAuthException;
          };
      };
      code = 400;
  }})
  Successfully logged in with Facebook... 
  123
  result Optional({
      id = 120008981838163;
      name = "Nisha Ios";
  })
  Did Logout of Facebook
  </code></pre>
  
  <p>Here is my code in AppDelegate.swift:</p>
  
  <pre><code>import UIKit
  import CoreData
  import FBSDKCoreKit
  
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate,  {
  
      var window: UIWindow?
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
  
          FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
  
          return true
      }
  
  
      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -&gt; Bool {
  
          var handled=FBSDKApplicationDelegate.sharedInstance().application(app, open: url,
                                                                              sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
  
  return handled
  }
  
      func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
           FBSDKAppEvents.activateApp()
      }
  </code></pre>
  
  <p>Here is my code in ViewController.swift:</p>
  
  <pre><code>import UIKit
  import FBSDKLoginKit
  import FBSDKCoreKit
  
  
  class ViewController: UIViewController, UITextFieldDelegate, FBSDKLoginButtonDelegate,  {
  
  
      @IBOutlet var emailField: UITextField!
  
      @IBOutlet var passField: UITextField!
  
      @IBOutlet var customButton: FBSDKLoginButton!
  
  
      @IBOutlet var myView: UIView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.emailField.delegate = self;
          self.passField.delegate = self;
  
        customButton.readPermissions=["email","public_profile"]
          customButton.delegate=self
  
          customButton.addTarget(self, action: #selector(handleCustomFBLogin), for: UIControlEvents.touchUpInside)
  
   func handleCustomFBLogin(){
  
     //  FBSDKLoginManager().logIn(withReadPermissions: ["email","public_profile"], from: self)
      //   { (result, error) -&gt; Void in
      //  if error != nil {
         //   print("custom FB Login Failed",error)
         //       }
      //}
                  self.showEmail()
                  print(123)
        }
  
  
      func showEmail()
      {
          FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "email, id, name"]).start {
              (connection, result, err) in
            if(err == nil)
             {
                  print("result \(result)")
              }
             else
              {
                  print("error \(err)")
              }
          }
  
      }
  
      public func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
  
          if error != nil
          {
              print(error)
              return
  
          }
          else{
              print("Successfully logged in with Facebook... ")
  
          }
          //showEmail()
      }
  
      func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!){
  
          print("Did Logout of Facebook")
  
      }
  </code></pre>
  
  <p>Here in the func handleCustomFBLogin(), I have commented some code. If I uncomment them I can't get the username or id and only get the code 2500 error. </p>
  
  <p>Can Someone tell me what I'm doing wrong? Also help me to login with a new user instead of automatically log in with the same user? 
  Thanks so much in advance :-)</p>