ios - 如何从不同变量的结果输出中获取电子邮件、姓名和图像
问题描述
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)
}
})
}
}
输出是:
可选({电子邮件=“rajput.abhishek660@gmail.com”;“first_name”= Abhishek;id = 1760800260695143;“last_name”= Rajput;名称=“Abhishek Rajput”;图片={数据={高度=200;“is_silhouette " = 0; url = "platform-lookaside.fbsbx.com/platform/profilepic/…;; 宽度 = 200; }; }; })
解决方案
你可以试试
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
它
推荐阅读
- python - 从其他应用程序调用功能到主应用程序
- html - 位置粘性不适用于列标题
- php - 当数据库中有 1 条记录时,Laravel 显示重复
- python - Pandas DF 堆叠过滤器不起作用,范围出现错误
- nlp - 斯坦福 CoreNLP 使用文件列表时如何跳过失败?
- javascript - Javascript 迭代和检查数组元素的最佳方法
- google-cloud-platform - 使用 Cloud Shell 定义最近的 Google 数据中心位置
- heroku - Heroku 错误日志 L10(输出缓冲区溢出)
- python - 自定义现有颜色条
- azure - 用于计划触发器的 Azure 数据工厂 CI/CD 不起作用