ios - Swift facebook 登录无法收到电子邮件?
问题描述
大家好,我正在使用DTSocialMediaLogin进行社交媒体登录(Facebook、Google、Twitter),除 Facebook 外,所有这些都可以使用。当我尝试登录 Facebook 时,它没有被记录,因为“电子邮件”没有收到。
正如您在图像上看到的那样,没有关于即将到来的数据的电子邮件。
这是权限部分:
func login(from viewController: UIViewController, done: @escaping(_ status: Bool, _ message: String, _ user: DTFacebookUser?) -> Void) {
let login = FBSDKLoginKit.LoginManager()
login.defaultAudience = .everyone
if scopes.count == 0 {
scopes = ["public_profile", "email"]
}
login.logIn(permissions: scopes, from: viewController) { (result, error) in
DispatchQueue.main.async {
if error != nil {
done(false, error!.localizedDescription, nil)
}
else if let result = result {
if result.isCancelled && result.declinedPermissions.count > 0 {
done(false, "facebook_cancel_declined", nil)
}
else {
//let userID = result.token?.userID
self.graph(str: "/me?fields=email,name", done: done)
}
}
}
}
}
这是登录操作:
@objc func actionFacebook() {
self.socialLogin.login(with: .Facebook, from: self) { (error, user) in
// user.name, user.email, user.id, user.profileImageURL
if user == nil {
return
}
var text = "FACEBOOK LOGIN\n"
text = "\(text)\nFull Name: \(user!.name)"
text = "\(text)\nEmail: \(user!.email)"
text = "\(text)\nUser ID: \(user!.id)"
text = "\(text)\nImage: \(user!.profileImageURL)"
print(text)
if user!.email == "" {
return
}
if user!.name == "" {
return
}
if self.passSignType == "Login"
{
ServiceManager.shared.Authenticate(Phone: "", MobilePin: "", Email: user!.email, Password: "", ProviderName: "Facebook", ProviderId: user!.id, ProviderToken: "", Name: user!.name, Username: user!.name, ActionType: "Login", callbackSuccess: { (response) in
HUD.flash(.label("hudAccountLogin".localized()), delay: 1.0) { _ in
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.dismiss(animated: true) {
}
NotificationCenter.default.post(name: Notification.Name(rawValue: "UserLogged"), object: nil)
}
}) { (response) in
HUD.flash(.label("hudFailed".localized()), delay: 1.0) { _ in
}
}
}
}
我无法解决问题 电子邮件无法在 Facebook 上发送...
解决方案
post logIn(permission ..) API 使用 GraphRequestConnection 来获取用户信息。
func getFbUserProfileInfo() {
let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me", parameters: ["fields" : "id,first_name,last_name,email,name"], tokenString: AccessToken.current?.tokenString, version: Settings.defaultGraphAPIVersion, httpMethod: .get)) { (connection, values, error) in
if let res = values {
if let response = res as? [String: Any] {
let username = response["name"]
let email = response["email"]
}
}
}
connection.start()
}
推荐阅读
- python - 如何将 GIF 动画写入 matplotlib 中的类文件缓冲区?
- android - 从 MYSQL PHP Slim 改造 Recycler 视图
- python - 如何使用相机参数计算像素之间以厘米为单位的世界距离?
- google-apps-script - 如何自动运行 Google Apps 脚本并自动更新 google sheet?
- javascript - 通过主题设置变色主题
- centos6 - 更改用户所有权以匹配组?
- java - ActiveMQ 消息代理上的消息过期
- android - 在firebase数据库中写入数据时权限被拒绝
- sql-server - 从数据库中每个表的每一列中获取数据 | SQL 服务器
- reactjs - Heroku 应用程序成功但未成功部署