Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Login Error - Unknown Error building URL (com.facebook.sdk.core error 3)

I'm getting this error when trying to log in with Facebook: Optional(Error Domain=com.facebook.sdk.core Code=3 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Unknown error building URL.}) I read in other posts it's a bug in version sing 4.39.0 of FBSDKLoginKit and the solution is downgrading to 4.38.o Now that gave me another error: Firebase Auth Interop/FIRAuth Interop.h' file not found in the FIRAuth.m #import <FirebaseAuthInterop/FIRAuthInterop.h> As I'm new to social logins and the guide in Facebook developer page is not up to date with swift and some is in obj-c I might mistranslated it to swift. Can you spot where is the problem? Also FBSDKLogin framework is highlighted in red in frameworks folder, and all the framework inside pods/Frameworks folder. Here's the code: AppDelegate

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: ({_,_ in
        }))

        UNUserNotificationCenter.current().delegate = self

        var error: NSError?
        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        } catch let error1 as NSError{
            error = error1
            print("could not set session. err:\(error!.localizedDescription)")
        }
        do {
            try AVAudioSession.sharedInstance().setActive(true)
        } catch let error1 as NSError{
            error = error1
            print("could not active session. err:\(error!.localizedDescription)")
        }
        window?.tintColor = UIColor.blue

        // Use Firebase library to configure APIs
        FirebaseApp.configure()

        // goggle only
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self

        // Facebook SDK
//        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)


//        return true
    }

The open URL where I put both Google sign in and Facebook:

// start google sign in methods
    @available(iOS 9.0, *)
    func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
        -> Bool {
            // google only
//            return
//                GIDSignIn.sharedInstance().handle(url,
//                                                     sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
//                                                     annotation: options[UIApplicationOpenURLOptionsKey.annotation])

            // both google and facebook

            let googleDidHandle = GIDSignIn.sharedInstance().handle(url,
                                                                       sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                                       annotation: options[UIApplicationOpenURLOptionsKey.annotation])


            guard let source = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String else { return false }
            let annotation = options[UIApplicationOpenURLOptionsKey.annotation] as? String

            let facebookDidHandle =  FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)



//            return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)



            return googleDidHandle || facebookDidHandle
    }

The login vc with Facebook method where I get the error:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
    if error == nil {
        print("User just logged in via Facebook")
        let credentials = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
        Auth.auth().signInAndRetrieveData(with: credentials) { (user, error) in
            if (error != nil) {
                print("Facebook authentication failed")
            } else {
                print("Facebook authentication succeed")
            }
        }//)
    } else {
        print("An error occured the user couldn't log in")
        print(error)
    }
}
like image 327
Vincenzo Avatar asked Dec 11 '18 22:12

Vincenzo


3 Answers

I found the problem. It's not code related. It seems to be a bug in the latest two versions of Facebook SDK so I downgraded it to

pod 'FBSDKCoreKit', '4.36.0'  
pod 'FBSDKLoginKit', '4.36.0'  
pod 'FacebookCore', '0.4'  
pod 'FacebookLogin', '0.4'

and it run smoothly. Dough for somebody version 4.38 solved the issue it wasn't the car for me. Hope this will be useful to others.

like image 174
Vincenzo Avatar answered Nov 09 '22 10:11

Vincenzo


This is a Facebook SDK bug in version 4.39.0 which is causing this error. In order to solve this bug, simply downgrade both CoreKit and LoginKit to 4.38.0, clear derived data as well as clean build folder (CMD + OPTION + SHIFT + K).

pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'

If you are using FacebookCore and FacebookLogin then do like the following.

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'
like image 24
shanezzar Avatar answered Nov 09 '22 11:11

shanezzar


Looks like there has been a hot fix for this 4.39.1 was released Jan 15, 2019 (a week in the future apparently)

https://developers.facebook.com/docs/ios/change-log-4x/

like image 23
Seamus Avatar answered Nov 09 '22 12:11

Seamus