TheM4hd1 / SwiftyInsta

Instagram Private API Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I get full page count without calling `everything`

emreond opened this issue · comments

Hello,

I like to get full page count for comments without fetching all comments. How can I achieve it? With below code, I can get the full count but I needed to wait for it finish for huge pages. I am thinking of two solutions;
1-) Starting this and suspend it after get page count (I am not sure how I can suspend it)
2-) Get exact page count with any other way

Actually what I want to achieve is that starting paging in the middle etc... As I see It gets string and I am not sure what value should I give.


handler.comments.all(forMedia: mediaID, with: .everything) { (mediaComments, commentArray, pagination, _) in
            debugPrint("Total Comments: \(mediaComments.comments)")
            debugPrint("Updating: \(updateCount)")
            debugPrint("Max Page: \(pagination.maxPagesToLoad)")
            debugPrint("Comments: \(commentArray.count)")
            updateCount += 1
        } completionHandler: { (result, pagination) in
            switch result {
            case .success(let comments):
                debugPrint("Current Comment Array Count: \(comments.count)")
                completion(comments)
            case .failure(let error):
                debugPrint(error)
            }
        }

If you need the comments count, you can simply call the handler.media.info(mediaId,completionHandler), but if you need the total pages, the easier way without fetching all data is to divide comment count by max_per_page count.
for example if each pagination returns maximum 50 comment, and total comments are 250, you can find total page like this: 250/50 = 5 pages. (but you should consider that this is not a stable/reliable way, since pagination can change by Instagram at anytime, but you can use for a loading indicator or displaying loaded percent on your app)

As I see pagination wants string as start ID. For example I want to start at page 10. Is it possible?

I taught you wanted to know how many pages are exists. So, No, the only way to fetch next_max_id is to call parent page first. you can use the updateHandler to fetch the first page and save the pagination.nextMaxId and use it for fetching next page whenever you wanted.

I taught you wanted to know how many pages are exists. So, No, the only way to fetch next_max_id is to call parent page first. you can use the updateHandler to fetch the first page and save the pagination.nextMaxId and use it for fetching next page whenever you wanted.

Hmmm as I search pageID is generated randomly. Therefore, I think it is impossible to get pageID for a specific page (like 10) :( Thank you for your help.