如何打印出来自
的图像print((result! as AnyObject).value(forKey: "picture.data.url") as? Any)
我知道下面会打印出数据和 url,但我只需要 URL 部分。
print((result! as AnyObject).value(forKey: "picture") as? Any)
有什么建议吗?
我正在使用 FacebookLogin SDK
最佳答案
NOTE: You can create the image URL on your own if you have the userId,
let facebookProfileUrl = "http://graph.facebook.com/\(userID)/picture?type=large"
这里是你如何从 facebook 登录中获取 id、姓名、电子邮件和个人资料图片 url。我在我的应用程序中使用此代码并且它有效。
func fetchFacebookFields() {
LoginManager().logIn(permissions: ["email","public_profile"], from: nil) {
(result, error) -> Void in
if let error = error {
print(error.localizedDescription)
return
}
guard let result = result else { return }
if result.isCancelled { return }
else {
GraphRequest(graphPath: "me", parameters: ["fields" : "first_name, last_name, email"]).start() {
(connection, result, error) in
if let error = error {
print(error.localizedDescription)
return
}
if
let fields = result as? [String:Any],
let userID = fields["id"] as? String,
let firstName = fields["first_name"] as? String,
let lastName = fields["last_name"] as? String,
let email = fields["email"] as? String
{
let facebookProfileUrl = "http://graph.facebook.com/\(userID)/picture?type=large"
print("firstName -> \(firstName)")
print("lastName -> \(lastName)")
print("email -> \(email)")
print("facebookProfileUrl -> \(facebookProfileUrl)")
APPDELEGATEOBJ.makeRootVC(vcName : "MainTabBarVC")
}
}
}
}
}
关于ios - 如何从 FacebookLogin 抓取图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59316898/