TheM4hd1 / SwiftyInsta

Instagram Private API Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User Followers

flamme0011 opened this issue · comments

In new version you added second arguments in closure body.
What is for second one? And how can I call it?

When I try to call like this it gives error

try handler.getUserFollowers(userId: userId, maxId: "" , searchQuery: "", completion: { (result) in
print(result)

})

The parameters are…
userId: Int is the pk of the profile you wanna get the followers of.
maxId: Optional<String> (I suggest maybe defaulting it to nil) is the value returned by the pagination model in order to fetch not only the first 200 (if I'm not mistaken) followers, but also the next 200, and so on.
searchQuery: String (I suggest maybe changing it to Optional<String> and defaulting it to nil) is part of a username or name and it is matched to return only appropriate values ("instagram" will return only accounts starting with "instagram" for instance, but the exact algorithm appears to be more complicated). Leave it an empty string "" to fetch everyone and everything.
completion: (Result<UserShortListModel>, _ maxId: String?) -> Void is the completion handler returning your results and the next maxId you need to pass to the same function in order to get the next page (if not nil).

I might spend some time documenting most of the methods in code if it's okay to you @TheM4hd1

Then if I set to maxId like Int.max then it will not work. Because of this it should be nil. Correct?

Correct.
maxId should either be nil or the value passed by completion.
It does not match the way PaginationParameters are used in FeedHandler, unfortunately, but it can be improved.

There are 3 ways, but 2 type of functions to receive followers

func getUserFollowers(username: String, paginationParameter: PaginationParameters, searchQuery: String, completion: @escaping (Result<[UserShortModel]>) -> ()) throws
func getUserFollowers(pk: Int, paginationParameter: PaginationParameters, searchQuery: String, completion: @escaping (Result<[UserShortModel]>) -> ()) throws
func getUserFollowers(userId: Int, maxId: String?, searchQuery: String, completion: @escaping (Result<UserShortListModel>, _ maxId: String?) -> ()) throws

Type 1.

Functions that accepts a PaginationParameter as a param, can automatically walks through pages and gives you final result.

Type 2.

Functions that accepts a maxId as param, are more efficient, because you can receive the first page by passing nil as maxId, the function will return you another maxId, this is the one you can use it to receive more data on future requests.

If you're using this function to receive all available followers to do some stuff on them, you can use functions with PaginationParameter because its more easier but slower(because it needs to receive all pages first, then returns you data).
But if you want to show more data by scrolling (like instagram scrolling, when scroll ended, it will receive new data) you should use functions that accept maxId


@sbertix
I was thinking about creating documentation, that would be really nice if you handle it.
I can help you with that too.

I see. Everything clear for me now. Thanks for your help.

And is there any way to get user followers faster? For example I am try to get user followers which has 75k and it takes too much time like 25 minutes in simulator.

if every page returns us about 200 user (I'm not sure about this, you should check)
75000/200 = 375
it means you need to send 375 request to instagram to receive all 75k followers.
if every request (send and receive) takes about 3 seconds, it will be something about 19 minutes to complete the requests.
in a good scenario if every request takes 1 second it can be something about 6 minutes to complete.
If you are working on an app like statistics, you should tell your users that this action may take a few minutes to complete.
The only way to speedup requests is set delay model to zero.
and because we need the next_max_id to receive next page's data, we can't use multi-threading here, so as I know, this is fastest way.

yes I understand you. Thanks for your help