cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Error in files_list_folder method

Error in files_list_folder method

Phoggbank
Explorer | Level 3

I am still trying to get over the initial "hump" writing my first Python Dropbox API. Eventually I would like to iterate through all the folders in a Dropbox account, then for each of those folders, iterate through all the image (JPG) files, writing any comments the user entered to a flat (text) file.

 

But baby steps first. I can't even get the files_list_folder method to work! Help, please!

 

My code:

 

print("Initializing Dropbox API...")
from dropbox import Dropbox


dbx = Dropbox("[appl id]")
result = dbx.files_list_folder('')

 

Output:

 

Initializing Dropbox API...
Traceback (most recent call last):
File "G:\pythonProject1\main.py", line 10, in <module>
result = dbx.files_list_folder('')
File "C:\Users\camorgan_2\AppData\Local\Programs\Python\Python39\lib\site-packages\dropbox\base.py", line 1952, in files_list_folder

 

r = self.request(
File "C:\Users\camorgan_2\AppData\Local\Programs\Python\Python39\lib\site-packages\dropbox\dropbox_client.py", line 323, in request res = self.request_json_string_with_retry(host,
File "C:\Users\camorgan_2\AppData\Local\Programs\Python\Python39\lib\site-packages\dropbox\dropbox_client.py", line 479, in request
_json_string_with_retry
return self.request_json_string(host,
File "C:\Users\camorgan_2\AppData\Local\Programs\Python\Python39\lib\site-packages\dropbox\dropbox_client.py", line 604, in request _json_string
raise BadInputError(request_id, r.text)
dropbox.exceptions.BadInputError: BadInputError('553b370bfef7427db853a0aa8b1b9bae', 'Error in call to API function "files/list_folder
": The given OAuth 2 access token is malformed.')

2 Replies 2

Здравко
Legendary | Level 20

@Phoggbank wrote:
...

dbx = Dropbox("[appl id]")
...

": The given OAuth 2 access token is malformed.')


🤔 Did you provide OAuth 2 access token (or refresh token) within the Dropbox object instantiation? 🤷

Application code and secret are not any kind of access token! I think it's self explanatory. 😉 For easy start copy corresponding code out from some example and use within your application.

Hope this helps.

Greg-DB
Dropbox Staff

This "The given OAuth 2 access token is malformed" error is referring to the oauth2_access_token parameter value you're passing to the Dropbox constructor. It means that the value you're passing in is not a valid Dropbox access token. You'll need to correct that to make sure you're passing in a valid access token for that parameter, and make sure there are no stray characters, e.g., extra whitespace, etc.

 

In the code you shared here, you have "[appl id]" as the value for that parameter, which I presume is just a placeholder you used to redact the actual value. The actual value should be either a short-lived access token (which starts with "sl.") or a long-lived access token (which doesn't start with "sl.", and would generally be 64 characters long). You can find more information on how to get an access token in the OAuth Guide.

 

Given the term "appl id" it sounds like it's possible that you're actually passing in your "app key", not an access token. Note that your "app key" just identifies an app, and does not enable access to an account. App keys are generally just around 15 characters long.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?