2017-03-15 98 views
0

我正試圖獲得Facebook Accesstoken。當我打印accessToken時,它會返回一個帶有appId和authenticationToken的對象,我如何解析出令牌? 我使用下面的代碼:Swift get Facebook AccessToken

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 

     } 
    } 
+0

http://stackoverflow.com/a/42266558/5 461400試試這個 –

+0

你可以直接獲取訪問令牌'FBSDKAccessToken.current()' –

回答

1

你試圖解析該令牌是一個結構

實際令牌是:

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 

    } 
}