ios - Facebook api swift 当前用户为零

标签 ios swift facebook facebook-graph-api

我对 Facebook api 有疑问。登录并成功解包用户 token 后,我在获取用户配置文件时遇到问题:它是零。

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()
    }
}

即使我尝试使用 let userProfile = UserProfile(userId: (AccessToken.current?.userId)!) 获取配置文件手册,它在所有参数中也采用 nil,但它已初始化用户.有趣的是,对于那个 UserProfile.current,它可以拍摄用户照片。它可以是什么?如何通过其他方式获得完整的用户名?

最佳答案

android也有这个问题。 获得访问 token 后,您应该加载配置文件(收听 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(completion: {
            profile, error in
            if let updatedUser = profile {
                print("finally got user: \(updatedUser)")
            } else {
                print("current user still not got")
            }
        })
    }
}

关于ios - Facebook api swift 当前用户为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978868/

相关文章:

ios - 在 Swift 的某个时间停止 AVAudioPlayer

facebook - 代表用户喜欢一个页面?

javascript - 如何监听后台变化(Parse Server)

ios - Interface Builder 文件中的未知类信息

ios - 如何限制只对某些用户删除 TableView 中的行?

facebook - Facebook,IE和P3P

android - 有什么方法可以使用 ContactsContent Provider 发布 Facebook 状态吗?

ios - 如何在 xcconfig 文件中配置完整的 URL

swift - 插入图像后 NSTextView 未更新

ios - 如何使用swift在IOS App中缓存过期图像