2016-04-05 38 views
0

我不知道是什麼導致了這個問題,使用Firebase的FB登錄功能完美無缺。但現在我遇到了INVALID_CREDENTIALS以下錯誤。swift - invalid_credentials錯誤,而firebase的Facebook身份驗證?

我試着從Facebook上刪除應用程序,然後再運行,然後檢查https://developers.facebook.com/每節,但同樣的問題仍然存在。

此錯誤帶有打印( 「是(錯誤)」)行打印的accessToken完美了。

我已經搜索,但我找不到可能的解決方案,爲什麼會出現此問題,我該如何解決它?

錯誤域= FirebaseAuthentication代碼= -11「(錯誤代碼:INVALID_CREDENTIALS)提供的驗證憑證無效。」的UserInfo = {細節= { 「providerErrorInfo」:{}},NSLocalizedDescription =(錯誤代碼:INVALID_CREDENTIALS)。提供無效的認證證書}

@IBAction func loginFb_clicked(sender: AnyObject) { 

    let facebookLogin = FBSDKLoginManager() 


    facebookLogin.logInWithReadPermissions(["email"], fromViewController: self) { (facebookResult: FBSDKLoginManagerLoginResult!, facebookError: NSError!) in 

     if facebookError == nil { 

      if FBSDKAccessToken.currentAccessToken() == nil { 

       print("FOUND NIL!") 

      } 
      else if(facebookResult.isCancelled) { 

       print("Cancelled") 

      } 
      else { 

       let accessToken = FBSDKAccessToken.currentAccessToken().tokenString 
       print(accessToken) 

       DataService.ds.REF_BASE.authWithOAuthProvider("facebook", token: accessToken, withCompletionBlock: { 
        error, authData in 

        if error != nil { 
         print("yes \(error)") 
        } 
        else { 

         let dateFormatter = NSDateFormatter() 
         dateFormatter.dateFormat = "MMMM dd, yyyy hh:mm" 
         let stringDate = dateFormatter.stringFromDate(NSDate()) 
         print("createdAt: " + stringDate) 

         let user = 
          ["id": authData.providerData["id"] as! String, 
           "accessToken": authData.providerData["accessToken"] as! String, 
           "provider": authData.provider!, 
           "displayName": authData.providerData["displayName"] as! String, 
           "email": authData.providerData["email"] as! String, 
           "profileImageURL": authData.providerData["profileImageURL"] as! String, 
           "token": authData.token as String, 
           "createdAt": stringDate] 


         let uuidString:String = authData.providerData["id"] as! String 
         DataService.ds.REF_USERS.childByAppendingPath("facebook:"+uuidString) 
          .observeSingleEventOfType(.Value, withBlock: { snapshot in 
           print("Solved snapshot is:") 
           print(snapshot.value) 
           if !snapshot.exists() { 
            print("USER NOT EXIST ON DB!") 

            // DataService.ds.REF_USERS_KEY.childByAppendingPath("facebook:"+uuidString).setValue("1") 
            DataService.ds.createFirebaseUser(authData.uid, user: user) 

           } 
           else { 
            print("USER EXIST ALREADY......................") 
            DataService.ds.REF_USERS.childByAppendingPath("facebook:"+uuidString).updateChildValues(user) 
           } 
          }) 


         print("Successfully logged in with facebook. \(accessToken)") 
         print("Logged in! \(authData)") 

         NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: KEY_UID) 
         self.performSegueWithIdentifier(SEGUE_LOGGED_IN, sender: nil) 
        } 
       }) 

      } 
     } 
    } 
} 
+1

您是否確認DataService.ds.REF_BASE是有效的Firebase參考? – Jay

+0

是的,沒有問題。即使我在這個範圍內獲得了accessToken。這個錯誤立即發生。所有的線路都很好。 – tobeiosdev

+0

注意確定傳遞給authWithOAuthProvider()的令牌是否無效,或者是否傳遞給FBSDKLoginManager()的憑證。你能得到堆棧跟蹤並驗證錯誤發生在哪裏?你如何驗證令牌是有效的?如果您嘗試使用令牌直接使用SDK進行身份驗證,它會起作用嗎?版本信息? – Kato

回答

0

這個問題從高級設置中添加白IP列表發生developer.facebook.com。檢查你的設置,如果你認爲你沒有添加它,刪除。它會被解決。