ios - 在 iOS Swift 中获取 Facebook 封面照片 URL
问题描述
当使用 Facebook 的图形资源管理器图形路径时,我能够使用以下方法获取用户的封面照片 URL:
connection.add(GraphRequest(graphPath: "/me/albums")) { httpResponse, result in ...
然后找到名称为“Cover Photos”的 id 并使用图形请求:
connection.add(GraphRequest(graphPath: ("/" + id + "/photos"))) { httpResponse, result in
然后从封面照片相册中获取第一个和最近的 id
然后最后使用图形请求:
connection.add(GraphRequest(graphPath: ("/" + id + "/picture"))) { httpResponse, result in
获取封面照片的 URL。
但是,在执行最终图形请求时,出现错误:
UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Response is a non-text MIME type; endpoints that return images and other binary data should be fetched using NSURLRequest and NSURLSession}
我无法使用 NSURLRequest 或 NSURLSession 来获取 URL。需要明确的是,在 Facebook Graph Explorer 中使用“/”+ id +“/picture”时,我能够获取封面照片 URL。但是,它不适用于 iOS。我相信我在以下方面拥有正确的权限:
let loginButton = LoginButton(readPermissions: [ .publicProfile, .userPhotos ])
解决方案
func findCoverPhotoPicture(id: String) {
print("find cover url", id)
print("https://graph.facebook.com/" + id + "/picture")
let imgURL = "https://graph.facebook.com/" + id + "/picture"
do {
let covImg: UIImage = try UIImage(data: Data(contentsOf: URL(string: imgURL)!))!
self.picView.image = covImg
} catch {
print(error)
}
}
推荐阅读
- selenium - 在 azure devops 中运行 selenium 测试用例时遇到错误
- laravel - 具有预加载关系的 Laravel 模型
- postgresql - Postgresql 获取前 1000 个数据并将 10 x 10 传输到另一台服务器上的另一个数据库
- dynamics-crm - FaultException`1:不正确的属性值类型 System.String- 如何找出导致错误的字段,Dynamics CRM,
- .net - Objective C 等效于 .Net WebClient 上传文件
- php - 为什么我在循环中填充数组变量时为空?
- python - steamworks InitiateGameConnection() 中是否有类似的 python 函数?
- r - 为什么从 RStudio 运行脚本时遇到 R 致命错误
- mount - 使用 mtpmount 和 dokany 进行 MTP 热拔出 - 是否严格要求卸载?
- postgresql - 使用 Postgresql JSON 字段作为映射的实体的 Spring Boot JPA 投影