2016-09-15 10 views
1

私はParseFacebookUtilsV4を使用していますが、fb idkは今のところコンソールに印刷するためにユーザー情報を取得することに問題があるようです。問題は、要求を開始するブロックが実行されていないように見えることです。なぜなら、デバッグするたびに開始完了ハンドラをスキップするように見えるからです。アカウント情報を取得できませんParse&FB SDK

// View controller code 
     PFFacebookUtils.facebookLoginManager().loginBehavior = .web 

     var loginTask = PFFacebookUtils.logInInBackground(withReadPermissions: []) 

     loginTask.continue({ (bfTask) -> Any? in 

      print("I'm here") 

      let request = FBSDKGraphRequest(graphPath:"me", parameters: ["fields":"id,email,name,first_name,last_name,picture"] ) 
      print(request) 
      request?.start { 

       (connection, result, error) in 

       print(result) 

      } 
      return "" 
     }) 

// App delegate config 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     let configuration = ParseClientConfiguration { 
      $0.applicationId = "xxxx" 
      $0.clientKey = "xxxxx" 
      $0.server = "https://parseapi.back4app.com" 
     } 
     Parse.initialize(with: configuration) 

     PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions) 

     PFTwitterUtils.initialize(withConsumerKey: "xxxxx", consumerSecret: "xxxxx") 

     // Override point for customization after application launch. 
     return true 
    } 

答えて

1

ここで私はFacebookのリクエストに使用している機能です。ブロックリクエストを使用しています:

func loadFacebookUserDetails() { 

    // Define fields we would like to read from Facebook User object 
    let requestParameters = ["fields": "id, email, first_name, last_name, name"] 

    // Send Facebook Graph API Request for /me 
    let userDetails = FBSDKGraphRequest(graphPath: "me", parameters: requestParameters) 
    userDetails.startWithCompletionHandler({ 
     (connection, result, error: NSError!) -> Void in 
     if error != nil { 
      let userMessage = error!.localizedDescription 
      let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert) 

      let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil) 
      myAlert.addAction(okAction) 
      self.presentViewController(myAlert, animated: true, completion: nil) 

      PFUser.logOut() 
      return 
     } 

     // Extract user fields 
     let userId:String = result.objectForKey("id") as! String 
     let userEmail:String? = result.objectForKey("email") as? String 
     let userFirstName:String? = result.objectForKey("first_name") as? String 
     let userLastName:String? = result.objectForKey("last_name") as? String 



     // Get Facebook profile picture 
     let userProfile = "https://graph.facebook.com/" + userId + "/picture?type=large" 

     let profilePictureUrl = NSURL(string: userProfile) 

     let profilePictureData = NSData(contentsOfURL: profilePictureUrl!) 


     // Prepare PFUser object 
     if(profilePictureData != nil) 
     { 
      let profileFileObject = PFFile(name:"profilePic.jpeg",data:profilePictureData!) 
      PFUser.currentUser()?.setObject(profileFileObject!, forKey: "ProfilePic") 
     } 

     PFUser.currentUser()?.setObject(userFirstName!, forKey: "Name") 
     PFUser.currentUser()?.setObject(userLastName!, forKey: "last_name") 



     if let userEmail = userEmail 
     { 
      PFUser.currentUser()?.email = userEmail 
      PFUser.currentUser()?.username = userEmail 
     } 



     PFUser.currentUser()?.saveInBackgroundWithBlock({ (success, error) -> Void in 


      if(error != nil) 
      { 
       let userMessage = error!.localizedDescription 
       let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert) 
       let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil) 
       myAlert.addAction(okAction) 
       self.presentViewController(myAlert, animated: true, completion: nil) 
       PFUser.logOut() 
       return 


      } 


      if(success) 
      { 
       if !userId.isEmpty 
       { 
        NSUserDefaults.standardUserDefaults().setObject(userId, forKey: "user_name") 
        NSUserDefaults.standardUserDefaults().synchronize() 


        dispatch_async(dispatch_get_main_queue()) { 
         self.dismissViewControllerAnimated(true, completion: nil) 
        } 

       } 

      } 

     }) 


    }) 

} 
関連する問題