cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Listing files using Dropbox Python

Listing files using Dropbox Python

sambapy
Helpful | Level 5
Go to solution

I am trying to access files stored on my Dropbox using the offical Dropbox SDK for Python.. I tried a few ways of putting in the directory name whose contents I wanted to have listed based off of a script taken from this link https://practicaldatascience.co.uk/data-science/how-to-use-the-dropbox-api-with-python. Following the instructions in this website, I created an App, generated a dropbox access token (which produced 'long-gibberish'), and gave myself read permissions for Files and Folders.

When I login to Dropbox through the website, the folder structure for the folder that I want to access looks like so: Folder/ SubFolder/ SubSubFolder.

 

I get the following error when calling the function:

dropbox_list_files('Folder/SubFolder/SubSubFolder')


Error getting list of files from Dropbox: ApiError('short-gibberish', ListFolderError('path', LookupError('not_found', None)))

 

DROPBOX_ACCESS_TOKEN = 'long-gibberish' 
def dropbox_connect():
    """Create a connection to Dropbox."""

    try:
        dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
    except AuthError as e:
        print('Error connecting to Dropbox with access token: ' + str(e))
    return dbx

def dropbox_list_files(path):
    """Return a Pandas dataframe of files in a given Dropbox folder path in the Apps directory.
    """

    dbx = dropbox_connect()

    try:
        files = dbx.files_list_folder(path).entries
        files_list = []
        for file in files:
            if isinstance(file, dropbox.files.FileMetadata):
                metadata = {
                    'name': file.name,
                    'path_display': file.path_display,
                    'client_modified': file.client_modified,
                    'server_modified': file.server_modified
                }
                files_list.append(metadata)

        df = pd.DataFrame.from_records(files_list)
        return df.sort_values(by='server_modified', ascending=False)

    except Exception as e:
        print('Error getting list of files from Dropbox: ' + str(e))

 I would like to get some help on how to set the right path.

12 Replies 12

sambapy
Helpful | Level 5
Go to solution

I didn't share the access token considering security reasons, and replaced it instead.

For e.g. the app key looks like in my case  like 'ge.BP55pDouXGwKHtJ-Z2ohkoWUDiDIUvHDATvcBeCsNxEpCT7-HLGuWHWI6rl15UBimLfsAhi7N7XJ4n2sP31P_Tzxp13Izab44hsCxDEFP3qXYZw'

 

Is it supposed to be like that or something else?

Sorry, I am unfamiliar with these new concepts. Thanks for your responses.

Здравко
Legendary | Level 20
Go to solution

OMG!

Yes, such things don't have to be shared (can be dangerous - direct access to your account on the wider public)!

That what you are sharing looks like access token. It's NOT application key.

The application key is ID of the application you have registered. You need this key, not the access token. The last error comes from erroneous places free text on place where client ID is expected (nothing related to access token). You application ID (or key) can be seen on your application page when you select your application here (the same link I post above, but seems you skipped it). Find out your application key there and put it on the APP_KEY var initialization into the example.

Hope now all will be Ok.

sambapy
Helpful | Level 5
Go to solution

Thanks for helping resolving the issue.

Need more support?