错误代码 2500 Facebook 登录 Swift 3.0

Error code 2500 Facebook login on Swift 3.0

我正在尝试将 Facebook 登录集成到 iOS 10 应用程序 swift 3.0。 在将 FacebookSDK 设置到应用程序后,我收到错误代码 2500,如下所示:

控制台错误代码:

body =     {
    error =         {
        code = 2500;
        "fbtrace_id" = FpAkfsaBAFc;
        message = "An active access token must be used to query information about the current user.";
        type = OAuthException;
    };
};
code = 400;
}})

loginViewController 上的 loginButton 函数:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {

    fetchProfile()
    print("@@@@Completed Login@@@@")

}

在 loginVC 上获取 Facebook 个人资料功能:

func fetchProfile() {


    let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]

    FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: { (connection, user, requestError) -> Void in

        if requestError != nil {
            print(requestError)
            print("There are some error during getting the request from fb")
            return
        }

        self.email = (user?["email"] as? String)!
        self.firstName = (user?["first_name"] as? String)!
        self.lastName = (user?["last_name"] as? String)!

        self.nameLabel.text = "\(self.firstName) \(self.lastName)"
        print("My fbname is " + self.firstName)
        print(self.lastName)

        var pictureUrl = ""

        if let picture = user?["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String {
            pictureUrl = url
            print(pictureUrl)
        }

    })
}

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

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

    return true
}



func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

搜索过关于堆栈溢出的类似问题,但没有在 swift 3.0 上工作,如果有人可以就此问题提出建议,我们将不胜感激,谢谢,祝你有美好的一天!

如错误消息所述,您缺少 access_token。在发出请求之前先做一个控制,检查 access_token 是否为 nil,然后再请求一个新的。之后你应该可以提出你的要求了。

我已经解决了这个问题,因为在 iOS10 中默认禁用钥匙串访问,在 Capabilities[=14] 下启用 KeyChain Sharing =] 并且 Facebook 登录工作正常!