2015-06-29 38 views
0

我正在使用解析在我的應用上使用Facebook登錄。無法使用帶有解析登錄的FBSDKGraphRequest

這是我的代碼:

//set permissions required 
    let permissionsArray = ["user_about_me"] 
    //log in 
    PFFacebookUtils.logInWithPermissions(permissionsArray, block: { (pUser, pError) -> Void in 


     //if user is correctly loggin 
     if pUser != nil && pError == nil{ 


      //request facebook for more informations 
      var request = FBSDKGraphRequest(graphPath: "me", parameters: nil) 

      request.startWithCompletionHandler({ (connection, result, error) -> Void in 
       NSLog("\(error)") 

      }) 

     } 
    }) 

我正確登錄與解析,但是當我'要求我的信息,一直有這樣的消息:

com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={ 
    body =  { 
     error =   { 
      code = 2500; 
      message = "An active access token must be used to query information about the current user."; 
      type = OAuthException; 
     }; 
    }; 
    code = 400; 
}} 

回答

0

我已經使用用於登錄的Facebook SDK,我使用返回的令牌進行Parse登錄,然後我可以獲取用戶的信息。

我已經解決了我的問題與此代碼:

FBSDKLoginManager().logInWithReadPermissions(["user_about_me"], handler: { (result, error) -> Void in 

     if let resultLogin : FBSDKLoginManagerLoginResult = result as? FBSDKLoginManagerLoginResult{ 

      //if no error 
      if error == nil 
       && resultLogin.grantedPermissions.contains("user_about_me"){ 
        var accessToken = FBSDKAccessToken.currentAccessToken().tokenString 
        var expiration = FBSDKAccessToken.currentAccessToken().expirationDate 
        var facebookID = FBSDKAccessToken.currentAccessToken().userID 

        PFFacebookUtils.logInWithFacebookId(facebookID, accessToken: accessToken, expirationDate: expiration, block: { (pUser, pError) -> Void in 

         //if user is correctly loggin 
         if pUser != nil && pError == nil{ 


          //request facebook for more informations 
          var request = FBSDKGraphRequest(graphPath: "me", parameters: nil) 

          request.startWithCompletionHandler({ (connection, result, error) -> Void in 
           NSLog("\(error)") 

          }) 

         } 
        }) 
      } 
     } 
    })