Error recieved: Error Domain=com.facebook.sdk.core Code=8 “(null)”

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

Hello so i keep getting this error:

Error recieved: Error Domain=com.facebook.sdk.core Code=8 "(null)"  

My project works fine when i programmed using xcode 8 and swift 3. But now i downgraded to use xcode 7.3.1 and swift 2.3 and i get this error.

Below is my appdelegate file:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {          let viewController = ViewController(nibName: nil, bundle: nil)         viewController.view.backgroundColor = UIColor.whiteColor()         let navController:UINavigationController = UINavigationController(rootViewController: viewController)          self.window = UIWindow(frame: UIScreen.mainScreen().bounds)         self.window?.backgroundColor = UIColor.darkGrayColor()         self.window?.rootViewController = navController         self.window!.makeKeyAndVisible()          //facebook         FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)          //Google         var error: NSError?         GGLContext.sharedInstance().configureWithError(&error)         assert(error == nil, "Error Configuring google services \(error)")         GIDSignIn.sharedInstance().delegate = self          return true     }   func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {         return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])     }      func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {         return  FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)     }      func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {          if error != nil {             print ("Error sigining in: \(error.localizedDescription)")             return         }     }  

SignInController.swift file:

class SignInController: UIViewController, FBSDKLoginButtonDelegate, GIDSignInUIDelegate, GIDSignInDelegate {     //starts here     let fbButton:FBSDKLoginButton = {         let button = FBSDKLoginButton()         button.readPermissions = ["public_profile", "email", "user_friends"]         return button     }()      override func viewDidLoad() {         super.viewDidLoad()          self.title = "Sign In"         self.view.backgroundColor = UIColor.whiteColor()          if FBSDKAccessToken.currentAccessToken() == nil {             print("I got token: \(FBSDKAccessToken.currentAccessToken()?.tokenString)")             view.addSubview(fbButton)             fbButton.center = view.center             fbButton.delegate = self             self.fetchprofile()         }          else {             print("Dont have token")             self.view.addSubview(fbButton)             fbButton.center = self.view.center             fbButton.delegate = self             }          GIDSignIn.sharedInstance().uiDelegate = self         GIDSignIn.sharedInstance().delegate = self         let googleButton = GIDSignInButton(frame: CGRect(x: 30, y: 150, width: 100, height: 50))         view.addSubview(googleButton)     }      override func didReceiveMemoryWarning() {         super.didReceiveMemoryWarning()         // Dispose of any resources that can be recreated.     }      func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {         if error != nil {             print(error.localizedDescription)             return         }         print("I'm in")         fetchprofile()     }      func fetchprofile() {          print("Getting profile")         print("FB version: \(FBSDKSettings.sdkVersion())")         print("Tokensssss:  \(FBSDKAccessToken.currentAccessToken()?.tokenString)")          let parameters = ["fields": "email"]          let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: parameters, HTTPMethod: "GET")          graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in              if error != nil {                 print("Error recieved: \(error.debugDescription)")                 return             }              guard let email = result["email"] as? String else {                 return             }              print("Email: \(email)")         }     }      func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {         return true     }      func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {         print("Logged out")     }         override func touchesBegan(touches: Set, withEvent event: UIEvent?) {         self.view.endEditing(true)     }  } 

Error receiving:

Error recieved: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={     body =     {         error =         {             code = 2500;             "fbtrace_id" = CgykKyskOcd;             message = "An active access token must be used to query information about the current user.";             type = OAuthException;         };     };     code = 400; }} 

Please could someone assist. Thanks

Here is my info-plist file:

CFBundleDevelopmentRegionenCFBundleExecutable$(EXECUTABLE_NAME)CFBundleIdentifier$(PRODUCT_BUNDLE_IDENTIFIER)CFBundleInfoDictionaryVersion6.0CFBundleName$(PRODUCT_NAME)CFBundlePackageTypeAPPLCFBundleShortVersionString1.0CFBundleURLTypesCFBundleURLSchemesfb{{myFB-Id}}CFBundleTypeRoleEditorCFBundleURLSchemescom.googleusercontent.apps.99471515633-84bp5qjrl8jqf0drm10aucsrrepgta12CFBundleTypeRoleEditorCFBundleURLSchemes{{Bundler-id}}CFBundleVersion1LSApplicationCategoryTypeFacebookAppID{{myFB-id}}FacebookDisplayName{{myFB-displayName}}LSApplicationQueriesSchemesfbapifb-messenger-apifbauth2fbshareextensionLSRequiresIPhoneOSUILaunchStoryboardNameLaunchScreenUIMainStoryboardFileMainUIRequiredDeviceCapabilitiesarmv7UISupportedInterfaceOrientationsUIInterfaceOrientationPortraitUIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRightUISupportedInterfaceOrientations~ipadUIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDownUIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRight

回答1:

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) } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!