python - Dropbox /delta ignoring cursor -
i'm trying list files on dropbox business.
the dropbox python sdk not support dropbox business i'm using python requests module send post requests https://api.dropbox.com/1/delta directly.
in following function there repeated calls dropbox /delta, each of should list of files along cursor.
the new cursor sent next request next list of files.
but same list. though dropbox ignoring cursor sending.
how can dropbox recognise cursor?
def get_paths(headers, paths, member_id, response=none): """add eligible file paths list of paths. paths queue of files download later member_id dropbox member id response example response payload unit testing """ headers['x-dropbox-perform-as-team-member'] = member_id url = 'https://api.dropbox.com/1/delta' has_more = true post_data = {} while has_more: # if ready-made response not supplied, poll dropbox if response none: logging.debug('requesting delta {}'.format(post_data)) r = requests.post(url, headers=headers, json=post_data) # raise exception if status not ok r.raise_for_status() response = r.json() # set cursor in post data next request # fixme: fix cursor setting post_data['cursor'] = response['cursor'] # iterate items possible adding file list [removed example] # stop looping if no more items available has_more = response['has_more'] # clear response response = none
the full code @ https://github.com/blokeley/dfb/blob/master/dfb.py
my code seems similar official dropbox blog example, except use sdk can't because i'm on dropbox business , have send additional headers.
any greatly appreciated.
it looks you're sending json-encoded body instead of form-encoded body.
i think change json
data
in line:
r = requests.post(url, headers=headers, data=post_data)
edit here's complete working code:
import requests access_token = '<redacted>' member_id = '<redacted>' has_more = true params = {} while has_more: response = requests.post('https://api.dropbox.com/1/delta', data=params, headers={ 'authorization': 'bearer ' + access_token, 'x-dropbox-perform-as-team-member': member_id }).json() entry in response['entries']: print entry[0] has_more = response['has_more'] params['cursor'] = response['cursor']
Comments
Post a Comment