收到错误:错误域 = com.facebook.sdk.core 代码 = 8“(空)”

Posted

技术标签:

【中文标题】收到错误:错误域 = com.facebook.sdk.core 代码 = 8“(空)”【英文标题】:Error recieved: Error Domain=com.facebook.sdk.core Code=8 "(null)" 【发布时间】:2016-10-17 01:45:13 【问题描述】:

你好,所以我一直收到这个错误:

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

当我使用 xcode 8 和 swift 3 进行编程时,我的项目工作正常。但现在我降级为使用 xcode 7.3.1 和 swift 2.3,我得到了这个错误。

下面是我的 appdelegate 文件:

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 文件:

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<UITouch>, withEvent event: UIEvent?) 
        self.view.endEditing(true)
    


接收错误:

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;

请有人帮忙。谢谢

这是我的 info-plist 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fbmyFB-Id</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.googleusercontent.apps.99471515633-84bp5qjrl8jqf0drm10aucsrrepgta12</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>Bundler-id</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSApplicationCategoryType</key>
    <string></string>
    <key>FacebookAppID</key>
    <string>myFB-id</string>
    <key>FacebookDisplayName</key>
    <string>myFB-displayName</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

【问题讨论】:

您是否为此添加了钥匙串?因为对于 facebook 登录,您必须添加钥匙串 如果没有,则添加 如果你想要演示,我可以带领你完成 facebook 登录 @Jecky 钥匙串是什么意思?是的,你能给我看一个演示吗 对不起,我认为您正在使用 swift 3.0 并且根据 swift 3.0 我评论了您的帖子 【参考方案1】:

更新你的.plist文件https://gist.github.com/himanshu-benzatine/1ad78c7d17051c36f60b934b64725f31

//将此代码放入您的按钮点击方法中

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)

    
   )

// 将此代码添加到您的 AppDelegate.swift 文件中

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)

【讨论】:

gist.github.com/himanshu-benzatine/… 如下更新您的 .plist 文件 我发布了我的 info-plist 并仔细检查了但仍然有同样的错误 @user3497437 发生什么样的错误告诉我?您使用的是 swift 版本 2 还是 3.0? 我正在使用 swift 版本 2。我的错误发布在问题页面上。 “接收错误”。在你提到它没有成功之前,我还添加了你在 appdelegate 文件中提到的内容。当我使用 swift 3 时,它可以工作,但必须降级到 swift 2,现在出现此错误 @user3497437 我也在使用 swift 2.0,我的代码在 swift 2.0 中运行良好

以上是关于收到错误:错误域 = com.facebook.sdk.core 代码 = 8“(空)”的主要内容,如果未能解决你的问题,请参考以下文章

InfluxDB 和 Grafana 跨域错误

需要在 Glassfish 上启动域,出现错误:“目录”中没有域

错误域 = NSCocoaErrorDomain 代码 = 3840 “字符周围的值无效

反应.js |如何摆脱 Codesandbox 中的跨域错误

运行时遇到错误(域 = LaunchServicesError,代码 = 0)[重复]

Autodesk Forge 跨域请求被阻止错误