我正在使用firebase Facebook auth。用户可以成功登录,我可以从firebase在Facebook登录后获得用户配置文件图像,但我需要自定义图像以获得更好的质量。我无法使用此使用user profile类的代码获取用户配置文件图像。尽管类似的android代码工作得很好。
我的自定义Facebook按钮代码。先在课堂上签名。

  @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))

但是这个代码在这里返回零。我也试过在Facebooklogin按钮的成功中添加这段代码,它仍然返回nil。解决办法是什么。

最佳答案

成功登录后,您将获得令牌而不是配置文件。
意思是仍然没有。
必须加载配置文件。您可以参考similair question
使用UserProfile.current直接获取化身url。例子:
https://graph.facebook.com/1410901795642099/picture?type=square&width=10&height=10

关于ios - swift 4:无法从Facebook获取用户个人资料图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45185338/

10-12 00:15
查看更多