iOS Facebook SDK Error Domain com.facebook.sdk Code 2 and Code 7
Yes, after you see this error, if you go to Settings, you will see that the setting for this app is turned "OFF". But the problem in this case is that the user was never prompted to allow access -- i.e. the setting was turned to OFF automatically on first time access. If the user was asked, then of course that is understandable, but this is not the case (it's as if the SDK silently and automatically pressed Don't Allow for the user). That's why this is a problem.
Before you read any further, I want to note that once the setting is set, you cannot simply repeat the process to test it, because once the setting is set, it will never ask the user (even deleting and reinstalling the app does not help). To test this issue, you need to reset the permissions by going to Settings -> General -> Reset -> Reset Location & Privacy, before you can try to replicate this again.
From testing, I've discovered that if you have offline_access in the permissions you are requesting for the first time, then it will give this login error (and not prompt the user and set the permission to OFF). The SDK does not check and tell you that this permission is not allowed; it just fails to login.
com.facebook.sdk error 2 on iOS
Turns out: a com.facebook.sdk error 2 can translate into a number of things. I'm looking for some kind of Facebook SDK error translation table, but I'm unable to find one. In my case:
The com.facebook.sdk error 2 happened because the connection timed out. Users who got this error had a bad network/WiFi connection.
We implemented an error logging system, which logged the error details every time an error happened while logging into Facebook. In those logs we could see a com.facebook.sdk error 2 happening quite a lot, but it being resolved every time the user tried to log in again after a few seconds.
It might be due to my inability to find the right documentation, but I was and still am quite frustrated about the vagueness of these SDK errors. There is a lot of documentation about permission asking (which can result into the com.facebook.sdk error 2), but apparently this error can be caused by more things. It would be nice to see this documented somewhere as well.
Error recieved: Error Domain=com.facebook.sdk.core Code=8 (null)
Update your .plist file https://gist.github.com/himanshu-benzatine/1ad78c7d17051c36f60b934b64725f31
// put this code in your button click method
if FBSDKAccessToken.currentAccessToken() != nil {
FBSDKLoginManager().logOut()
return
}
let login:FBSDKLoginManager = FBSDKLoginManager()
login.logInWithReadPermissions(["public_profile", "email", "user_friends" ], handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if(error != nil){
FBSDKLoginManager().logOut()
}else if(result.isCancelled){
FBSDKLoginManager().logOut()
}else{
//Handle login success
self.returnUserData()
}
})
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
print("User Logged Out")
}
func returnUserData()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email, friends, birthday, cover, devices, picture.type(large)"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
print("Error: \(error)")
}
else
{
print(result)
}
})
}
// Add this code in your AppDelegate.swift file
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
com.facebook.sdk.core error 8
Make sure your permissions are typed correctly
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if error == nil {
println("login complete")
self.performSegueWithIdentifier("showLogin", sender: self)
}else{
println(error.localizedDescription)
//com.facebook.sdk.core error 8.
}
}
Why am I getting com.facebook.sdk.login error 308?
For Xcode8 - iOS10,
Enable Keychain Sharing within Capabilities tab of target fixed my issue.
More details can be found here : https://github.com/facebook/facebook-sdk-swift/issues/51
For Xamarin Studio (Suggested by @Kenneth),
Add the Entitlements.plist file to Custom Entitlements under the iOS Bundle Signing
options in the iOS project.
Can someone help me with the error below? I am trying to log into Facebook for my app
This are two different errors, for which each you can use Google to find out what could be wrong.
For the first error, it indicates that the user cancelled the login. Do you get this directly after hitting "Login with Facebook"? Can you debug the access token you have? Is it still valid?
For the second error, the key message is 'Invalid application 676311875766710'. Could it be that you try to login with a normal user, whilst the app is in development mode? When your app is in that mode, only Testers, Developers and Admins defined under the "Roles" tab of the App Dashboard can login.
Are you sure the App ID is correct in the plist? Is the App name also correct entered? Is the iOS platform correctly configured in the App Dashboard?
Related Topics
-Webkit-Overflow-Scrolling: Touch' Broken for Initially Offscreen Elements in iOS7
How to Add Pagination in UItableview.
Sync Video in Avplayerlayer and Avplayerviewcontroller
Hls Video Streaming on iOS/Safari
How to Handle a File Sent with 'Open In...' from Another App to My Own iOS App
iOS Add Button to Widget Extension
Passing Values from One View Controller to Another in Swift
My App Is Getting Crashed on UIdocumentpickerviewcontroller
Customize Google Maps Blue Dot for Current Location
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
Gcm Support for iOS Application When Application in Background or Killed
App Could Not Authenticate with Facebook and Firebase After Conversion to Swift 3 Syntax
Swift: Is Correct to Use Stored Properties as Computed Properties
How to Change Select Box Background Without Losing The Right Arrow on Mobile Safari
Load Custom Error HTMLstring When Wkwebview Loadrequest Fails