gpt4 book ai didi

ios - Swift iOS 中的 Facebook 相册访问

转载 作者:行者123 更新时间:2023-11-29 05:56:43 27 4
gpt4 key购买 nike

我想在我的 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 相册吗

最佳答案

看一下这部分代码,它为您提供 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

关于ios - Swift iOS 中的 Facebook 相册访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55078995/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com