We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Mgymnasts
3 years agoExplorer | Level 4
dbx.users_get_current_account() works but dbx.files_list_folder('').entries returns Error
I am able to use OAuth and can confirm access to my dropbox account using the dropbox API. But when I run dbx.files_list_folders('').entries. I am getting dropbox eceptions.ApiError: ApiError('string...
Mgymnasts
3 years agoExplorer | Level 4
I appreciate the suggestions! I went in and redid the OAuth to get a new stored_token and now when I run this I am not getting an error, but I also can't see the list of folders/files in the account. When my code gets to
for entry in dbx.files_list_folder('').entries:
print(entry.name)
It is stepping right over the print as if dbx.files_list_folder(").entries isn't even there.
Here is the code I am running (function being called that isn't returning what I expect)
def list_files_in_folder(folder_path,dbx😞
"""
Creates a list of the files found in the folder on Dropbox.
Parameters:
folder_path (string): The path to the folder
dbx: enables dropbox access
Returns:
files (list): List of Files in the folder
"""
try:
result = dbx.files_list_folder(folder_path)
files = [entry.name for entry in result.entries if isinstance(entry, dropbox.files.FileMetadata)]
return files
except dropbox.exceptions.ApiError as e:
print(f'Error listing folder contents: {e}')
return []
*************************IN MAIN************************
try:
try:
dbx = dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=d_app_key, app_secret=d_app_secret)
# Get information about the current user's account
account_info = dbx.users_get_current_account()
# # Access various properties of the user's account
account_id = account_info.account_id
display_name = account_info.name.display_name
email = account_info.email
is_verified = account_info.email_verified
# Print the user's account information
print(f"Account ID: {account_id}")
print(f"Display Name: {display_name}")
print(f"Email: {email}")
for entry in dbx.files_list_folder('').entries:
print(entry.name)
# Specify the Dropbox folder path you want to check or create
dropbox_folder_path = '/SaveRx/DataForSaveRx/'
processed_path = f'{dropbox_folder_path}/Processed/' #Not using currently
# Enable SSL certificate validation for requests to Dropbox
dbx._session.verify = True
# Get the list of files in the folder
current_files = list_files_in_folder(dropbox_folder_path, dbx)
print(current_files)
for file in current_files:
print(file)
Здравко
3 years agoLegendary | Level 20
Mgymnasts wrote:......, but I also can't see the list of folders/files in the account. When my code gets tofor entry in dbx.files_list_folder('').entries:print(entry.name)It is stepping right over the print as if dbx.files_list_folder(").entries isn't even there.
Mgymnasts, Is there any chance your application is App folder application (i.e. no full access and only list app's own folder only)? If so, put something in your application folder and let's see if something changes. You can also print out entries count. 😉
Good luck.
- Mgymnasts3 years agoExplorer | Level 4
Yes! Thanks! It was right in front of my face...
I really appreciate the advice! Thank you!
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!