I'm using v4.8
of the Facebook iOS SDK and developing for iOS 8+
. I'm also using v1.11.0
of the Parse framework
I'm wanting to get access to Facebook via ACAccount
& ACAccountStore
classes. The login works perfectly, but after I get access, I need to convert the ACAccount
into FBSDKAccessToken
in order to login to the Parse framework:
Here's my Swift code:
let accountStore = ACAccountStore()
let socialAccount = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierFacebook)
let appID = NSBundle.mainBundle().infoDictionary?["FacebookAppID"] as? String ?? ""
let permissions = ["user_birthday", "user_relationships", "user_location", "user_about_me"]
accountStore.requestAccessToAccountsWithType(socialAccount, options: [ACFacebookAppIdKey: appID, ACFacebookPermissionsKey: permissions]) {
(granted: Bool, error: NSError!) in
var token: FBSDKAccessToken? = nil
if let socialAccount = accountStore.accountsWithAccountType(socialAccount).last as? ACAccount, let userID = socialAccount.username where granted {
token = FBSDKAccessToken(tokenString: socialAccount.credential.oauthToken, permissions: permissions, declinedPermissions: nil,
appID: appID, userID: userID, expirationDate: NSDate.distantFuture(), refreshDate: NSDate.distantFuture())
}
if let token = token {
print("token \(token.tokenString) \(token.permissions) \(token.appID) \(token.userID) \(token.expirationDate) \(token.refreshDate)")
PFFacebookUtils.logInInBackgroundWithAccessToken(token, block: nil)
}
}
I get this error: error: Parse::InvalidSessionError (Code: 251, Version: 1.11.0)
What am I doing wrong?