user_photos 在 Swift 中列出访问权限
user_photos List access in Swift
当我尝试使用 user_photos 权限从 FacebookLogin 检索数据时,
我收到访问令牌无效 209 的错误。
我想这是因为我试图将数据保存在一个非类型匹配的变量中。
谁能告诉我如何访问从 Facebook 检索到的照片的 ID?
print(result["photos"])
给我:
Optional({
data = (
{
"created_time" = "2015-07-26T20:57:23+0000";
id = 920478361357710;
},
{
"created_time" = "2015-02-14T20:24:23+0000";
id = 961789147179683;
name = "szlangini kickdown";
},
}
您可以试试这个代码:
let parmas = ["fields" : "id, name"]
let request = FBSDKGraphRequest.init(graphPath: "me/photos", parameters: parmas
, HTTPMethod: "GET")
request.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result : AnyObject!, error: NSError!) -> Void in
let listPhoto = result["data"]
guard let unWrappedPhotos = listPhoto as? [AnyObject] else {
return
}
for dict in unWrappedPhotos {
guard let id = dict["id"] as? String else {
break
}
print(id)
}
}
当我尝试使用 user_photos 权限从 FacebookLogin 检索数据时, 我收到访问令牌无效 209 的错误。
我想这是因为我试图将数据保存在一个非类型匹配的变量中。
谁能告诉我如何访问从 Facebook 检索到的照片的 ID?
print(result["photos"])
给我:
Optional({
data = (
{
"created_time" = "2015-07-26T20:57:23+0000";
id = 920478361357710;
},
{
"created_time" = "2015-02-14T20:24:23+0000";
id = 961789147179683;
name = "szlangini kickdown";
},
}
您可以试试这个代码:
let parmas = ["fields" : "id, name"]
let request = FBSDKGraphRequest.init(graphPath: "me/photos", parameters: parmas
, HTTPMethod: "GET")
request.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result : AnyObject!, error: NSError!) -> Void in
let listPhoto = result["data"]
guard let unWrappedPhotos = listPhoto as? [AnyObject] else {
return
}
for dict in unWrappedPhotos {
guard let id = dict["id"] as? String else {
break
}
print(id)
}
}