Swift 4:无法从Facebook获取用户个人资料图片
问题描述:
我正在使用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按钮成功添加此代码,它仍然返回零。解决办法是什么。
答
成功登录后,您将获得令牌但不是配置文件。 这意味着UserProfile.current
仍然为零。
- 您必须加载简介。您可以参考similair question
- 使用
https://graph.facebook.com/{use-id}/picture?type=square&width=10&height=10
直接获得头像网址。例如: https://graph.facebook.com/1410901795642099/picture?type=square&width=10&height=10
您是否尝试过使用GraphRequest获取用户信息? – Markicevic
你应该检查你的'UserProfile.current'是否为零。 – Codus