1

I am trying to use FacebookLogin with Parse however i am receiving an error that,

The supplied Facebook session token is expired or invalid

every time I try to login using the code below.

import Foundation
import UIKit

class LoginViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let permissions = ["public_profile", "email"]
    PFFacebookUtils.logInWithPermissions(permissions) {
        (user, error) in
        if (user == nil) {
            if (error == nil) {
                println("User cancelled FB login")
            }else{
                println("FB login error: \(error)")
            }
        } else if user.isNew {
            println("User signed up and logged in with Facebook")

        } else {
            println("User logged in via Facebook")

        }
    }
}
Jay Blanchard
  • 33,530
  • 16
  • 73
  • 113
coderlyfe
  • 196
  • 1
  • 1
  • 9

1 Answers1

1

I had this error once and had to put this line before the login call in Objective-C

[FBSession.activeSession closeAndClearTokenInformation];

I can't seem to find the swift equivalent in the Parse SDK, and the Facebook SDK is still only in Objective-C.

You may have to add this line to an Objective-C file, and then call on it from your swift file. Check out this question on how to do that

How to call Objective-C code from Swift

Community
  • 1
  • 1
Mike V
  • 5,286
  • 6
  • 25
  • 35
  • 1
    no need to call that from objC - just include the framework, add a bridging header and it is available in swift – Daij-Djan Mar 12 '15 at 13:36
  • I don't get why people would want to rewrite everythingy in swift ;) you can easily use EVERYTHING written in c/c++/objC – Daij-Djan Mar 12 '15 at 13:37
  • Thanks @Daij-Djan I'm still a little unclear on how objC and swift work together – Mike V Mar 12 '15 at 13:45
  • I am still getting the same error, however at least I am now redirected to the facebook.com login that says I am already authorized. But when I click ok i get the same error as before. – coderlyfe Mar 12 '15 at 13:47
  • Have you added the FacebookAppID to your info.plist file? – Mike V Mar 12 '15 at 13:51
  • Also the the URL Scheme values: https://developers.facebook.com/docs/ios/getting-started – Mike V Mar 12 '15 at 13:52
  • Yeah and all the URL types info – coderlyfe Mar 12 '15 at 13:55
  • Is your facebook app still in sandbox mode? http://stackoverflow.com/questions/24423227/parse-facebook-login-fails-with-error-code-251 – Mike V Mar 12 '15 at 13:58