2015-10-05 42 views
0

我正在使用PFFacebookUtils.logInWithPermissions登錄到我的應用程序,但是,我第一次登錄實際登錄時正常工作,但我得到的FB錯誤爲code = 2500 An active access token must be used to query information about the current user。這會導致任何graphRequests失敗。初始解析FB登錄時沒有FB訪問令牌

如果我然後重新編譯到設備的代碼,這個錯誤不會發生,所有graphRequests工作正常。爲什麼應用程序在首次登錄時沒有獲取訪問令牌?此外,如果我從設備上徹底刪除應用程序並重新安裝,整個過程再次開始(首次嘗試時錯誤代碼= 2500)。

也許值得注意的是,這並沒有發生在先前版本的Parse和FB SDK中。我剛開始將這個應用程序轉移到iOS9中,這就是當這個問題出現時。

的Xcode 7.0.1,解析SDK v1.8.5,FacebookSDKs-IOS-20150910

+0

我還發現我可以通過殺死應用程序(並殺死我的意思是雙擊主頁+刷卡)和重新啓動來解決此事件。出於某種原因,下次啓動應用程序時,存在訪問令牌。 – booksix

+0

我也試着運行'FBSDKAccessToken.refreshCurrentAccessToken',希望它會DL一個新的令牌,但這會導致返回一個類似的錯誤消息(「沒有訪問令牌存在」) – booksix

+0

請更新您的問題與您的一些更多的細節碼。向我們展示代碼。 – adolfosrs

回答

1

我能夠首先調用FBSDK登錄方法,接着是解析SDK登錄方法(FBSDK回調內部來解決這個問題):

@IBAction func facebookButtonAction(sender: AnyObject) { 

    // Ensure that PFUser == nil - just in here because I heard it can help with some possible issues 
    PFUser.logOut() 

    let permissions = ["public_profile", "email", "user_friends"] 

    // First, login with FB’s SDK 
    let login: FBSDKLoginManager = FBSDKLoginManager() 
    login.logInWithReadPermissions(permissions, handler: {(result: FBSDKLoginManagerLoginResult!, error: NSError!) in 

     if (error != nil) { 
      NSLog("Process error") 
     } else { 
      if result.isCancelled { 
       NSLog("Cancelled") 
      } else { 
       NSLog("Logged in") 

       // Then with Parse’s, upon FB login success 
       PFFacebookUtils.logInWithPermissions(permissions) { (user, error) -> Void in 

        if let user = user { 
         if user.isNew { 
          print("User signed up and logged in through Facebook!」) 
          //... 
         } else { 
          print("User logged in through Facebook!") 
          //... 
         } 
        } else { 
         print("Uh oh. The user cancelled the Facebook login.") 
         //... 
        } 
       } 
      } 
     } 
    }) 
}