Facebook api swift当前用户为零 [英] Facebook api swift current user is nil
问题描述
func updateLoginStatus(){
如果let _ = AccessToken.current {
let currentUser = UserProfile.current
userName.text = currentUser?.fullName
userPictureView = UserProfile.PictureView(frame:blankUserImage.frame,profile: currentUser)
userPictureView!.clipsToBounds = true
userPictureView!.layer.cornerRadius = userPictureView!.bounds.width / 2
popUpView.addSubview(userPictureView!)
isLogged = true
updateLabels()
} else {
isLogged = false
userPictureView?.removeFromSuperview()
updateLabels()
}
}
即使我尝试通过使用获取个人资料手册,让userProfile = UserProfile(userId :( AccessToken.current?.userId)!)
它在所有参数上都为零,但是h ave初始化用户。有趣的部分是用UserProfile.current它已经取得用户图片。它可以是什么?如何通过其他方法获得完整的用户名?
这个问题在android中也发生了。
您应该在访问令牌后加载配置文件(在android中监听配置文件更改)。
我写了一个样本,只是在swift 3,Facebook iOS SDK 4.21.0中测试。
那么你可以得到updatedUser。
if let _ = FBSDKAccessToken.current(){
if let currentUser = FBSDKProfile.current(){
print(current user got:\(currentUser))
} else {
print(current user not got)
FBSDKProfile.loadCurrentProfile(完成:{
profile,
中的错误,如果let updatedUser = profile {
print(finally got user:\(updatedUser))
} else {
print(当前用户还没有)
}
})
}
}
I have a problem with Facebook api. After login and success unwrapping user token I have a problem with taking user profile: it's nil.
func updateLoginStatus() {
if let _ = AccessToken.current {
let currentUser = UserProfile.current
userName.text = currentUser?.fullName
userPictureView = UserProfile.PictureView(frame: blankUserImage.frame, profile: currentUser)
userPictureView!.clipsToBounds = true
userPictureView!.layer.cornerRadius = userPictureView!.bounds.width/2
popUpView.addSubview(userPictureView!)
isLogged = true
updateLabels()
} else {
isLogged = false
userPictureView?.removeFromSuperview()
updateLabels()
}
}
Even if I try to get profile manual by using let userProfile = UserProfile(userId: (AccessToken.current?.userId)!)
it also take nil at all parameters, but it have initialized user. Funny part is that with that UserProfile.current it have take user picture. What it can be? How I can get full user name by other methods?
This problem happend in android too. You should load profile (listen profile change in android) after you got access token. I write a sample and just tested in swift 3, Facebook iOS SDK 4.21.0. Then you can got updatedUser.
if let _ = FBSDKAccessToken.current() {
if let currentUser = FBSDKProfile.current() {
print("current user got: \(currentUser)")
} else {
print("current user not got")
FBSDKProfile.loadCurrentProfile(completion: {
profile, error in
if let updatedUser = profile {
print("finally got user: \(updatedUser)")
} else {
print("current user still not got")
}
})
}
}
这篇关于Facebook api swift当前用户为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!