2017-07-19 132 views
0

我正在使用firebase Facebook驗證。用戶能夠成功登錄我可以在Facebook登錄後從Firebase獲取用戶個人資料圖像,但我需要定製圖像以獲得更好的質量。 我使用這個使用UserProfile類的代碼無法獲取用戶個人資料圖片。雖然類似的代碼爲Android工作正常。Swift 4:無法從Facebook獲取用戶個人資料圖片

我的自定義Facebook按鈕代碼。寫在class SignUpFirst

@IBAction func facebookLogin(_ sender: AnyObject) { 
    let loginManager = LoginManager() 
    loginManager.logIn([ .publicProfile,.email], viewController: self) { loginResult in 
     switch loginResult { 
     case .failed(let error): 
      print(error) 
     case .cancelled: 
      print("User cancelled login.") 
     case .success(let grantedPermissions, let declinedPermissions, let accessToken): 
      //print("Logged in! \(accessToken)") 
      let credential = FacebookAuthProvider.credential(withAccessToken: accessToken.authenticationToken) 

      Auth.auth().signIn(with: credential) { (user, error) in 
       if let error = error { 
        //show error if failed 
        print(error.localizedDescription) 
        return 
       } 

       checkUser(firebaseUser: user!) 
      } 
     } 
    } 
} 

試圖在類SignUpSecond中獲取用戶配置文件圖像。

UserProfile.current?.imageURLWith(UserProfile.PictureAspectRatio.normal, size: CGSize(width: 10.0, height: 10.0)) 

但是這段代碼在這裏返回nil。我也嘗試在Facebooklogin按鈕成功添加此代碼,它仍然返回零。解決辦法是什麼。

+0

您是否嘗試過使用GraphRequest獲取用戶信息? – Markicevic

+0

你應該檢查你的'UserProfile.current'是否爲零。 – Codus

回答

相關問題