简体   繁体   中英

Getting Photos From Facebook

I use this functions to get a user's photos:

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

The problem is I only get 30 photos when I know to user has more photos than that.

How can I get ALL of the photos?

You need to pass in a limit parameter:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM