Search code examples
python-2.7dropbox-api

cant download file using drpbox API v2 python


Im trying to download file using the API v2 of dropbox this is my code:

#!/usr/bin/python2.7
import sys

import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError

TOKEN = '{TOKEN}'



if __name__ == '__main__':
    # Check for an access token
    if len(TOKEN) == 0:
        sys.exit("ERROR: Looks like you didn't add your access token. ")

    # Create an instance of a Dropbox class, which can make requests to the API.
    print("Creating a Dropbox object...")

    with dropbox.Dropbox(TOKEN) as dbx:
        try:
            md, res = dbx.files_download(path='/test/dropbox_test.txt')
        except dropbox.exceptions.HttpError as err:
            print('*** HTTP error', err)
    print("Done!")

but I'm getting error

BadInputError('1c38b505bb634f5985ef65e745c153f1', 'Error in call to API function "files/download": Your app is not permitted to access this endpoint because it does not have the required scope \'files.content.read\'. The owner of the app can enable the scope for the app using the Permissions tab on the App Console.')

I don't understand this error and how to fix it


Solution

  • Dropbox now uses "scopes" to configure what functionality an app can access. For example, to use the files_download method, which calls the /2/files/download endpoint, the app needs the files.content.read scopes. You can find more information about scopes on Dropbox in the Dropbox OAuth Guide.

    You can enable scopes for your app via "Permissions" tab of the app's page on the App Console.

    Note that this does not retroactively affect existing access tokens, so you'll need to get a new access token once that scope is enabled.