7

I'm trying to download a large Dropbox folder with a bunch of subfolders to an external harddrive using the scripts at: http://tilburgsciencehub.com/examples/dropbox/

import dropbox
from get_dropbox import get_folders, get_files
from dropbox.exceptions import ApiError, AuthError


# read access token
access_token = "sl.superlongstring"
 

print('Authenticating with Dropbox...')
try:
    dbx = dropbox.Dropbox(access_token, scope=['files.content.read', 'files.metadata.read'])
    print('...authenticated with Dropbox owned by ' + dbx.users_get_current_account().name.display_name)
except AuthError as err:
    print(err)

no errors here , correctly displays my name.

try:
    folders=get_folders(dbx, '/Audioboeken')
    print(folders)
    download_dir = r'L:\\00 Audioboeken'
    print('Obtaining list of files in target directory...')
    get_files(dbx, folder_id, download_dir)
except ApiError as err:
    print(err)
except AuthError as autherr:
    print(autherr)

This errors:

dropbox.exceptions.AuthError: AuthError('randomstringofnumbers, AuthError('missing_scope', TokenScopeError(required_scope='files.metadata.read')))

I've tried adding scope to the login request, but that doesn't seem to help..(not sure if I did that correctly)

App Permissions: The checkbox for files.content.read and files.metadata.read are checked.

user1692094
  • 302
  • 2
  • 5
  • 12

1 Answers1

29

The 'missing_scope' error indicates that while the app is permitted to use that scope, the particular access token you're using to make the API call does not have that scope granted. Adding a scope to your app via the App Console does not retroactively grant that scope to existing access tokens.

That being the case, to make any API calls that require that scope, you'll need to get a new access token with that scope.

Greg
  • 16,359
  • 2
  • 34
  • 44
  • 2
    Thanks! That indeed was the problem - I generated the access token before I set permissions. Pretty stupid that it's not clear that it's not retroactive when you change it.. – user1692094 Oct 05 '20 at 08:24
  • I don't get this.. when creating new app, it asked for scope. Scope is not a global setting... So, I don't understand what you mean to regenerate new access with new scope ? – MaXi32 Apr 01 '21 at 06:01
  • 1
    @MaXi32 When first registering the app, the "scopes" you choose are the maximum/default scopes that the app can use. (These can also be changed later if needed.) When connecting the app to a user account, either by generating an access token, or using the OAuth app authorization flow without specifying `scope`, these are the scopes that will be used. The app can also request a subset of these scopes during the OAuth app authorization flow by specifying the `scope` parameter. This determines which scopes the resulting access token will have. The scopes on an existing access token don't change. – Greg Apr 01 '21 at 14:09