You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Phoggbank
4 years agoExplorer | Level 3
Error in files_list_folder method
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.')
- Здравко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-DBDropbox 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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,910 PostsLatest Activity: 3 days agoIf 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 or Facebook.
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!