2016-09-20 91 views
2

我想用swift 3.0将Facebook登录集成到iOS 10应用程序中。 我得到错误代码2500为设置在FacebookSDK到应用程序后如下所示:错误代码2500在Swift 3.0上的Facebook登录

错误代码在控制台上:

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

loginButton功能上loginViewController:

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

    fetchProfile() 
    print("@@@@Completed [email protected]@@@") 

} 

在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,将不胜感激,如果任何人都可以在这个问题上,谢谢指教,有一个很好的天!

回答

1

我已经解决了这个问题的钥匙串接入已经在默认情况下iOS10被禁用,启用钥匙链共享能力和Facebook登录工作完美!

1

如错误消息所示,您缺少access_token。在提出请求之前先进行控制,并检查access_token是否为零,然后请求一个新的请求。之后,你应该可以提出你的要求。

+1

注意谢谢! – aznelite89