Xin chào, tôi đang cố truy xuất email của mình từ facebook khi tôi đang phát sdk ios bằng cách sử dụng nhanh chóng. Nền tảng iOS là 10, nhanh chóng 3 và Xcode 8. Tôi đã làm theo hướng dẫn trực tuyến nhưng gặp sự cố khi truy xuất email.Không thể truy xuất email từ facebook bằng cách sử dụng nhanh 3 và ios 10
dưới đây là mã của tôi:
if FBSDKAccessToken.current() == nil {
print("I got token")
let fbButton = FBSDKLoginButton()
fbButton.readPermissions = ["public_profile", "email", "user_friends"]
view.addSubview(fbButton)
fbButton.center = view.center
fbButton.delegate = self
self.fetchprofile()
}
else {
print("Dont have token")
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error != nil {
print(error.localizedDescription)
return
}
print("I'm in")
fetchprofile()
}
func fetchprofile() {
print("Getting profile")
let parameters = ["fields": "email"]
let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: parameters, httpMethod: "GET")
graphRequest.start(completionHandler: {(connection, result, error) -> Void in
if error != nil {
print("Error retrieving details: \(error?.localizedDescription)")
return
}
guard let result = result as? [String:[AnyObject]], let email = result["email"] else {
return
}
print("Email: \(email)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
self.view.backgroundColor = UIColor.red
})
}
và trong tập tin appdelegate.swift tôi:
//have both google and facebook signin. Google works but facebook doesn't
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation]) ||
FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
Tôi có thể đăng nhập và đăng xuất nhưng không thể lấy email.
CẬP NHẬT Thực ra khi tôi thực sự chuyển in (email), tôi có thể thấy nó trên bảng điều khiển dưới dạng câu lệnh tùy chọn. Tôi đang gặp rắc rối hiển thị nó mà không Statment tùy chọn
Người dùng có cấp quyền email cho ứng dụng không? Người dùng có địa chỉ email đã xác minh không? – WizKid
@WizKid thực sự tôi có thể thấy id email nhưng tùy chọn của nó Có vấn đề với tuyên bố bảo vệ – user3497437
Tôi có cùng một vấn đề – Carlo