user_photos Swift中的列表访问

时间:2015-11-18 10:46:15

标签: ios facebook swift list facebook-graph-api-v2.0

当我尝试使用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";
    },

}

1 个答案:

答案 0 :(得分:1)

您可以尝试以下代码:

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)
        }

    }