diff --git a/pyicloud/services/photos.py b/pyicloud/services/photos.py index e10e242..c50885c 100644 --- a/pyicloud/services/photos.py +++ b/pyicloud/services/photos.py @@ -49,14 +49,10 @@ class PhotosService(object): @property def albums(self): - request = self.session.get( - '%s/folders' % self._service_endpoint, - params=self.params - ) - response = request.json() albums = {} - for folder in response['folders']: + for folder in self._fetch_folders(): if not folder['type'] == 'album': + # FIXME: Handle subfolders continue album = PhotoAlbum(folder, self) @@ -64,6 +60,26 @@ class PhotosService(object): return albums + def _fetch_folders(self, server_ids=[]): + folders = server_ids if server_ids else "" + logger.debug("Fetching folders %s...", folders) + + data = json.dumps({ + 'syncToken': self.params.get('syncToken'), + 'methodOverride': 'GET', + 'serverIds': server_ids, + }) if server_ids else None + + method = 'POST' if data else 'GET' + request = self.session.request( + method, + '%s/folders' % self._service_endpoint, + params=self.params, + data=data + ) + response = request.json() + return response['folders'] + @property def all(self): return self.albums['All Photos']