从Facebook获取照片

时间:2015-07-22 13:10:29

标签: ios xcode facebook swift facebook-graph-api

我使用此功能获取用户的照片:

func getFacebookPhotos() {
    var request = FBSDKGraphRequest(graphPath:"/me/photos?fields=from,tags,images", parameters: nil);
    println("started request")
    request.startWithCompletionHandler(self.handler)
}

func handler(connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) {
    if error == nil {

        println(result)

        if (result["paging"]! != nil) {
            var after = result["paging"]!["cursors"]!["after"]! as! String
            var path = "/me/photos?fields=from,tags,images&after=" + after

            var request = FBSDKGraphRequest(graphPath: path, parameters: nil);
            println("started request")
            request.startWithCompletionHandler(self.handler)
        }
    } else {
        println(error)
    }
}

问题是,当我知道用户有更多照片时,我只能拍摄30张照片。

我如何获得所有照片?

1 个答案:

答案 0 :(得分:0)

您需要传递limit参数:

limit : This is the number of individual objects that are returned in each page. Note that this is an upper limit, if there are not enough remaining objects in the list of data, then less than this number will be returned. Some edges have an upper maximum on the limit value, for performance reasons. We will return the correct pagination links if that happens.

https://developers.facebook.com/docs/graph-api/using-graph-api/v2.4#paging