• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - facebook登录电子邮件不会很快(没有任何解决方案吗?)

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:00:45 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

你好,我需要一些帮助我一直在搜索关于这个主题的几个小时我尝试了很多东西但我做不到。

这是我的代码

let facebookReadPermissions = ["public_profile", "email"]

    func getFBUserData() {
    if((FBSDKAccessToken.current()) != nil){
        self.getFBUserDataSecondStep()
    } else {
        FBSDKLoginManager().logIn(withReadPermissions: self.facebookReadPermissions, from: self) { (result, error) in
            if error != nil {
                FBSDKLoginManager().logOut()
            } else if (result?.isCancelled)! {
                FBSDKLoginManager().logOut()
            } else {
                self.showLoadingAlert()
                let grantedPermissions = result?.grantedPermissions.map( {"\($0)"} )
                for permission in self.facebookReadPermissions {
                    if (grantedPermissions?.contains(permission))! {
                        print("permission: \(permission)")
                        // CONSOLE WRITING HERE LIKE THIS
                        // permission: public_profile
                        // permission: email
                    }
                }
                if (result?.grantedPermissions.contains("email"))! {
                    print("result is: \(result?.description ?? "nil")")
                    // result is: <FBSDKLoginManagerLoginResult: 0x1c0441920> ( console )
                    self.getFBUserDataSecondStep()
                } else {
                    FBSDKLoginManager().logOut()
                }
            }
        }
    }
}

    func getFBUserDataSecondStep(){
        FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
            if (error == nil){
                if let dict = result as? Dictionary<String, Any> {
                    print(result)
                    // COMING WITH LIKE THIS

                    //"first_name" = Esn;
                    //id = 10156020817443470;
                    //"last_name" = "\U00c7ak\U0131ralar";
                    //name = "Esn Banu\U015f \U00c7ak\U0131ralar";

                    //--// Where is email ?
                    var email = ""
                    var firstName = ""
                    var lastName = ""
                    var facebookId = ""
                    var facebookToken = ""
                    if let controlEmail = dict["email"] {
                        email = controlEmail as! String
                    }
                    if let controlFirstName = dict["first_name"] {
                        firstName = controlFirstName as! String
                    }
                    if let controlLastName = dict["last_name"] {
                        lastName = controlLastName as! String
                    }
                    if let controlFacebookId = FBSDKAccessToken.current().userID {
                        facebookId = controlFacebookId
                    }
                    if let controlFacebookToken = FBSDKAccessToken.current().tokenString {
                        facebookToken = controlFacebookToken
                    }
                        loginWithFacebook(email: email, firstName: firstName, lastName: lastName, facebookId: facebookId, accessToken: facebookToken, finishedClosured: { (state) in
                            if state {
                                let mainPage = self.mainStoryBoard.instantiateViewController(withIdentifier: "SWRevealViewController")
                                self.removeLoadingAlert()
                                self.passPage(page: mainPage)
                                return
                            }
                            self.removeLoadingAlert()
                            self.alert(message: "Giris Basarisiz")
                            return
                        })
                }
            } else {
                print(error?.localizedDescription)
            }
        })
}

我需要获取人员的电子邮件才能将用户注册到我的应用程序。但是无论我尝试什么,电子邮件都没有。我该如何解决这个问题,如果我尝试使用我的个人帐户没问题,但其他用户可能会出现问题。



Best Answer-推荐答案


    Note : This is in swift 4.0

    //giving permission
func getpermission(){
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
     //   fbLoginManager.loginBehavior = FBSDKLoginBehavior.web

        fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
            if (error == nil){
                let fbloginresult : FBSDKLoginManagerLoginResult = result!
                if fbloginresult.grantedPermissions != nil {
                    if(fbloginresult.grantedPermissions.contains("email"))
                    {
                        self.getFBUserData()
                        fbLoginManager.logOut()

                    }
                }
            }
        }

}
// Get all details from here
 func getFBUserData(){
        var fbId : String = ""
        var fbEmail : String = ""
        var fbName : String = ""
        var fbPickUrl : String = ""

        if((FBSDKAccessToken.current()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
                if (error == nil){
                    //everything works print the user data
                    print("Result111:\(String(describing: result)) "as Any)
                }
                let dict = result as! NSDictionary
                print("FB Email1st:\(dict)")

                fbId = dict["id"] as! String
                fbName = dict["name"] as! String
                fbEmail = dict["email"] as! String
 //get user picture url from dictionary
fbPickUrl = (((dict["picture"] as? [String: Any])?["data"] as? [String:Any])?["url"] as? String)!

print("FB ID: \(fbId)\n FB Email:\(fbEmail) \n FbName:\(fbName) \n FBProfileUrl:\(fbPickUrl)\n")


            })
        }

    }

关于ios - facebook登录电子邮件不会很快(没有任何解决方案吗?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147596/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap