如何从不同变量的结果输出中获取电子邮件,名称和图像

问题描述 投票:-2回答:1
 func getFBUserData(){
        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(result)                                    
                }
            })
        }
 }

输出是:

可选({email =“[email protected]”;“first_name”= Abhishek; id = 1760800260695143;“last_name”= Rajput; name =“Abhishek Rajput”; picture = {data = {height = 200;“is_silhouette “= 0; url =”platform-lookaside.fbsbx.com/platform/profilepic / ... ;; width = 200;};};})

ios swift xcode
1个回答
0
投票

你可以试试

if let res = result as? [String:Any] {
       print(res["first_name"])
       print(res["last_name"])
       print(res["name"])
       print(res["email"]) 
       if let picture = res["picture"] as? [String:Any] {                    
           if let data = picture["data"] as? [String:Any] {
                print(data["url"])
           } 
       }
}

您也可以使用Codable

© www.soinside.com 2019 - 2024. All rights reserved.