错误代码2500 Facebook登录Swift 3.0

时间:2016-09-20 03:10:43

标签: ios swift facebook-graph-api facebook-login swift3

我正在尝试使用swift 3.0将Facebook登录集成到iOS 10应用程序中。 在将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上工作,如果有人可以就此问题提出建议,那将不胜感激,谢谢,祝你有愉快的一天!

2 个答案:

答案 0 :(得分:1)

如错误消息所示,您错过了access_token。在发出请求之前进行控制并检查access_token是否为nil,然后请求新的请求。之后,您应该能够提出要求。

答案 1 :(得分:1)

我已经解决了这个问题,因为iOS10默认禁用了钥匙串访问权限,启用功能下的 KeyChain共享,Facebook登录功能完美!