Swift获得Facebook AccessToken

问题描述 投票:1回答:1

我正试图获得Facebook Accesstoken。当我打印accessToken时,它返回一个带有appId和authenticationToken的对象,如何解析令牌?我使用以下代码:

let loginManager = LoginManager()
    loginManager.logIn([ .publicProfile, .userFriends, .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("accessToken: " + String(describing: accessToken))
            break

        }
    }
ios swift xcode facebook
1个回答
3
投票

您尝试解析的令牌是一个结构

实际的令牌是:

accessToken.authenticationToken

你的代码应该是这样的:

let loginManager = LoginManager()
loginManager.logIn([ .publicProfile, .userFriends, .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("accessToken: " +  accessToken.authenticationToken)
        break

    }
}

推荐问答