我一直在整合FacebookSDK与堆栈溢出和一些教程,但它对我来说不能正常工作。我无法获取个人资料数据。甚至没有调用此方法。仅显示“完全登录”。登录过程正在运行,但注销选项永远不会出现在按钮上。我很感谢任何提示。
import Foundation
import UIKit
import FBSDKLoginKit
import FBSDKCoreKit
class mainView: UIViewController, FBSDKLoginButtonDelegate {
@IBOutlet weak var navigationBar: UINavigationBar!
@IBOutlet weak var mainImage: UIImageView!
@IBOutlet weak var getRecipeBtn: UIButton!
@IBOutlet weak var addImageBtn: UIButton!
let loginButton: FBSDKLoginButton = {
let button = FBSDKLoginButton()
button.readPermissions = ["email"]
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(loginButton)
loginButton.center = view.center
loginButton.delegate = self
if let token = FBSDKAccessToken.current() {
fetchProfile()
}
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
print("completed login")
}
func loginButtonWillLogin(_ loginButton: FBSDKLoginButton!) -> Bool {
return true
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
}
func fetchProfile() {
print("fetch profile")
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, id"]).start(completionHandler: { (connection, result, error) in guard
let result = result as? NSDictionary,
let email = result["email"] as? String,
let user_name = result["fist_name"] as? String,
let user_id = result["id"] as? String
else {
return
}
print(email)
})
}
}
以下是我的控制台日志部分:(我已将fbauth添加到info.plist。)
RecipeMaster [19428:630625] -canOpenURL:URL失败:“fbauth2:/” - 错误:“操作无法完成。(OSStatus error -10814。)” 完成登录
2017-02-08 22:48:23.308043 RecipeMaster [19428:640928] PAC提取失败,错误[NSURLErrorDomain:-1003]
2017-02-08 22:48:23.308482 RecipeMaster [19428:641029] [] nw_proxy_resolver_create_parsed_array PAC评估错误:NSURLErrorDomain:-1003
答案 0 :(得分:1)
您可能必须转到目标 - >功能并启用钥匙串共享(它允许访问您应用的钥匙串),according to this answer.
答案 1 :(得分:0)
我已经修复了第一个错误 -canOpenURL:网址失败:“fbauth2:/ 我在AppDelegate中设置了不同的方法(有3.0实施的答案) - > Facebook SDK sign in with Swift 3 iOS 10