Dropbox /delta 忽略光标

Dropbox /delta ignoring cursor

我正在尝试列出 Dropbox for Business 上的文件。

直接Dropbox Python SDK does not support Dropbox for Business so I'm using the Python requests module to send POST requests to https://api.dropbox.com/1/delta

在下面的函数中,重复调用了 Dropbox /delta,每个调用都应该得到一个文件列表和一个光标。

新游标随下一个请求一起发送,以获取下一个文件列表。

但它总是得到相同的列表。就好像 Dropbox 忽略了我发送的光标。

如何让 Dropbox 识别光标?

def get_paths(headers, paths, member_id, response=None):
    """Add eligible file paths to the list of paths.

    paths is a Queue of files to download later
    member_id is the Dropbox member id
    response is an example response payload for 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 is not supplied, poll Dropbox
        if response is None:
            logging.debug('Requesting delta with {}'.format(post_data))
            r = requests.post(url, headers=headers, json=post_data)
            # Raise an exception if status is not OK
            r.raise_for_status()

            response = r.json()

            # Set cursor in the POST data for the next request
            # FIXME: fix cursor setting
            post_data['cursor'] = response['cursor']

        # Iterate items for possible adding to file list [removed from example]

        # Stop looping if no more items are available
        has_more = response['has_more']

        # Clear the response
        response = None

完整代码位于https://github.com/blokeley/dfb/blob/master/dfb.py

我的代码看起来与 official Dropbox blog example 非常相似,除了它们使用我不能使用的 SDK,因为我在 Dropbox for Business 上并且必须发送额外的 headers.

如有任何帮助,我们将不胜感激

您发送的似乎是 JSON 编码正文,而不是表单编码正文。

我认为只需将这一行中的 json 更改为 data

r = requests.post(url, headers=headers, data=post_data)

编辑 这是一些完整的工作代码:

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()

    for entry in response['entries']:
        print entry[0]

    has_more = response['has_more']
    params['cursor'] = response['cursor']