Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Contact service only fetched first 500 contacts #114

Closed
wants to merge 1 commit into from

Conversation

joshim5
Copy link
Contributor

@joshim5 joshim5 commented Jan 15, 2017

The iCloud API only pulls 500 contacts at a time. Previously, the contacts service in this library would only fetch the user's first 500 contacts.

This PR resolves the issue, so that all of the user's contacts can be pulled when calling api.contacts.all()

Fixes #103

@torarnv
Copy link
Collaborator

torarnv commented Jan 20, 2017

Hmm, I think the startup endpoint should only be needed once, in the ctor, and should be able to update the self.params for future calls to /contacts, so that we don't end up with 3 requests per update.

@joshim5
Copy link
Contributor Author

joshim5 commented Jan 31, 2017

Could you be more specific about what you mean by "ctor"? The contacts API will only fetch 500 contacts with each step, so it is necessary to make one request per 500 contacts.

@torarnv
Copy link
Collaborator

torarnv commented Sep 24, 2017

Sorry, "ctor" -> "construtor" -> __init__ in python lingo.

Look at the code in photos.py, and how it polls the startup endpoint in __init__, updating self.params.

This is how the iCloud website works from what I've seen. The initial load calls out to the startup endpoint, for the initial set of data, which is then expanded by calls to eg the contacts endpoint for more data, or the changeset endpoint for diffs to existing data.

refresh_client in calendar.py is duplicating quite some logic, calling json() a bunch, etc. So I don't want to add to it by duplicating more.

@Quentame
Copy link
Collaborator

Here is what I get while having 503 contacts

Capture d’écran 2020-02-13 à 13 54 51

Can you rebase and fix your code ?

params_next.update({
'clientVersion': '2.1',
'prefToken': req.json()["prefToken"],
'syncToken': req.json()["syncToken"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'syncToken': req.json()["syncToken"],
'syncToken': self.response["syncToken"],

params_next = dict(self.params)
params_next.update({
'clientVersion': '2.1',
'prefToken': req.json()["prefToken"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'prefToken': req.json()["prefToken"],
'prefToken': self.response["prefToken"],

'limit': '0',
'offset': '0',
})
req = self.session.get(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is 2 requests to get 1 result ?

Please do 2 requests if more than 499 contacts only OR 1 request to get 0 to infinite contacts at once.

@Quentame Quentame added this to the 0.9.6 milestone Mar 19, 2020
@Quentame Quentame mentioned this pull request Mar 20, 2020
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contacts.all() limited to 500 contacts
3 participants