Take Your Search Game to the Next Level with Dropbox Dash  🚀✨ Curious how it works? Ask us here! 

Forum Discussion

og19's avatar
og19
New member | Level 1
2 months ago

Iterating through results of sharing_list_shared_links()

What is the right way to iterate through the results of calling sharing_list_shared_links()?

I have this code:

        # Initial request
        response = dbx.sharing_list_shared_links()

        print(f"{response=}")

        # Collect links from the first response
        shared_links.extend(response.links)

        # Pagination: Keep fetching more links if there’s a cursor
        while response.has_more:
            response = dbx.sharing_list_shared_links(cursor=response.cursor)
            print(f"{response=}")
            import time
            time.sleep(5)
            shared_links.extend(response.links)

But in the response, has_more is always True, and links is always empty:
response=ListSharedLinksResult(cursor='A4YpRtuxypdJPZLwT14cczKlj3_NdJ_ilHJ8HhSDnAppgs8s5TRvY1pZ2exgH-RodUHGeAneaVheVOqXPJCVYHLjPsuUU7efHqdAqnQEF5E9KGLiqK9Iw1N_9xLNHuLxJtY__0PFadfERo0slzmelluil75TDk1qbTw3DLLpTsms4wlUqnbPxij0M_jFIQ1TVvjdDg1Wd5qSlUtkDLWNSbjSP2Hlf-dG3fOJhn1Sc1k8Fa_WduIUP_dUgzzYEGBHtPWkhAfmTv1bm90qhCeymep-uxVhQFZsyndV9B3w04jaUh_4ke4k9uN9yPIfngouBCbHi8yNyADCAwzy4PlM9Iw9mZireWkWg8b4vsUvGleqfQJGoHhlwZc4EYXdtVZmk8TjzTkNS8RaOLWcWbd4KHz2J9e-DM8gK90veLgY8sTM4A', has_more=True, links=[])

response=ListSharedLinksResult(cursor='A4aH_GnTKrKPBzpzcN04A98ExsLrEEuZczB6YSg9o89eZDF7t_AIfpDJc9t1O_ySUazI6ZLxnearIWdKgH5TGizPPUzCGjqP26MqwZbzPmq-hKa9EVK_HcGJAzVttB1_hABkVAKYfXxfi9RUmAfxOS4dnYfnPJFBDk4ULq6XWGb7eO3U2nSlQC7REsCKjtYifwmIRkTYiBJT162zB-mFYyKsl-t8ajX9gHLx2fcAyiaaqpADN0P3tzLJxuZ2cTPPLlfWJ_POkgX92YA9zVfJRyvmjp6otMQg4QvQAMMQaNpL15eyxwkqBQo0lGuGAq0RYC1GJx9Jq7eo3PJqAHAGTHiy2JNJxMMswSG8Z3VXovvdjOm7UqbALfMdv-6-UcjWjgGKSBMMSYHtXUxv0482tRXsgxwIrwtew7w6_t6A8Uh0RQ', has_more=True, links=[])

response=ListSharedLinksResult(cursor='A4YUw1tIpSz33BlGqF1qLOrU1ee5ZzmQkBwzBMXfo8NT5Hq81-sdiPz6CNgA1-2Ayg6loNLZDKPOCngLiQ-sSSt9Jt9O8FG-tWPQVRA0QzC9FQoi5XZxVOxDwGIbI5DRvJ9y5FoK1cXy00-BWhgia_XepMgY-hfmMjHVCvI7i-_PbZ-TdAfkAoI_l19FRJOqD3i2lsstYpezS5VYIite6Br9L7nGABT4YIptci-1LQ6BFGOvfMElUR1N0ldtj-3nm2C_Xjx-irASX1t11x6Y1gfVWcw6ybGtqYCqfAKEP_CSGSQjrTdhPH_0ye3wVk7qKmdHGbl3JS4kW27N6XA1574qIrFyOexEocu7eH9z6vw-YxToaBeeQ26nYec7vHTBCP60Kfy2_UYpc6QIRazxJMROmIMu8mc-z8UOlKh9_kQsTg', has_more=True, links=[])

6 Replies

  • DB-Des's avatar
    DB-Des
    Icon for Dropbox Engineer rankDropbox Engineer

    Hi og19,

    Your code appears correct, and this can be confirmed by the fact that you are getting a successful (200) response from the API.

    Keep in mind that depending on the usage pattern and current state of the account, it is possible for the /sharing/list_shared_links endpoint to return successful responses containing an empty links list, with a new cursor and has_more set to true. Your app will still need to page through each response to retrieve all results. The exact size of the links list in any particular result and the number of pages used is not guaranteed and may vary by account and over time. The links list may sometimes contain no entries for some accounts and calls.

    That said, would it work for you to call /sharing/list_shared_links with the path set to the path of a each specific file in question, and direct_only set to True? This might scale more predictably, as it would avoid the issue of potentially having to page through multiple pages of empty results.

    • og19's avatar
      og19
      New member | Level 1

      Thanks DB-Des – 

      What is the correct way of interating through the results when links is empty and has_more is True? Is the cursor itself a link?

      I have printed out all the data that is being returned, as you can see – I'm not sure what else can be done.

      I do not know the paths a priori – I need to find all the links and expire all the ones that are older than a certain amount.

      • DB-Des's avatar
        DB-Des
        Icon for Dropbox Engineer rankDropbox Engineer

        og19,

        A cursor is encoded information associated with the API call that helps maintain the state between paginated requests. This information could include (but is not limited to), the time and date of the request, parameter values, account information, position of the last retrieved item, etc.

        Could you confirm what the highest amount of requests is that you have iterated through that contain empty links and has_more=True?

        Are you also able to provide 5-10 different 'X-Dropbox-Request-Id' response header values for requests that have returned empty links and has_more=True?

  • og19's avatar
    og19
    New member | Level 1

    Hi DB-Des, it goes on forever, and never stops, even before I put in the sleep of 5 seconds. 

    I'm using the Python SDK, so I'm not dealing with headers directly. Can you tell me what all you'd like printed out after each call and how to print it in Python and I'll re-run it and send it to you. 

    By the way, the reason I'm doing this in the first place is that Dropbox is lacking a feature to expire all links I've shared, that are older than a certain date, in bulk. The Dropbox web UX makes you do this one link at a time... which is unusable, because I have hundreds. 

    I've already +1'd this feature request, but it doesn't seem to be a priority for Dropbox, that's why I'm writing it myself.

    • DB-Des's avatar
      DB-Des
      Icon for Dropbox Engineer rankDropbox Engineer

      og19,

      Thank you for the additional information. I have passed the details of this report along to our engineering team for further analysis. I'll follow up here once I have an update.

  • DB-Des's avatar
    DB-Des
    Icon for Dropbox Engineer rankDropbox Engineer

    og19 

    Just following up to let you know the issue you reported with empty links responses when using sharing_list_shared_links() has been fixed. Responses should now contain data, as well as has_more=True if there are any additional entries.

    Let us know if you observe anything different on your end still.