我想在我的Swift应用程序中访问Facebook相册。我已经登录了该应用程序。然后,我使用Graph API进行调用以访问Facebook相册。结果为零。
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": ""], httpMethod: "GET")?.start(completionHandler: {(connection , result, error) -> Void in
if(error == nil){
guard let dict = result as? [String:Any], let albums = dict["data"] as? [[String:Any]] else {
return
}
}
})
任何人都可以帮助我在iOS中访问Facebook相册
答案 0 :(得分:0)
看看这部分代码,为您提供 Swift 中的相册数据。
func getMyAlbums(){
let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me/albums?fields=cover_photo,picture,name,count")) { httpResponse, result in
switch result {
case .success(let response):
self.parseAlbums(response: response)
case .failed(let error):
print("Graph Request Failed: \(error)")
}
}
connection.start()
}
func parseAlbums(response: GraphRequest.Response){
guard let responseDictionary = response.dictionaryValue else {
return
}
guard let data: NSArray = responseDictionary["data"] as? NSArray else {
return
}
for index in 0..<data.count {
let valueDict : NSDictionary = data[index] as! NSDictionary
let id = valueDict.object(forKey: "id") as! String
let count = valueDict.object(forKey: "count") as! NSNumber
let name = valueDict.object(forKey: "name") as! String
let pictureUrl = ((valueDict.object(forKey: "picture") as! NSDictionary)
.object(forKey: "data") as! NSDictionary)
.object(forKey: "url") as! String
let album = Album(id:id,name:name,coverUrl:pictureUrl,countImages:Int(count))
albums.append(album)
}
albums = albums.sorted(by: {$0.name < $1.name})
}
您还可以检查有关从facebook提取图片的项目: Facebook Photos Extracting App