Search code examples
pythongoogle-drive-apigoogle-oauthgoogle-api-python-client

Google Drive API: The user has not granted the app error


I'm following the Quickstart on https://developers.google.com/drive/api/v3/quickstart/python. I've enabled the drive API through the page, loaded the credentials.json and can successfully list files in my google drive. However when I wanted to download a file, I got the message

`The user has not granted the app ####### read access to the file`

Do I need to do more than putting that scope in my code or do I need to activate something else?

SCOPES = 'https://www.googleapis.com/auth/drive.file'
client.flow_from_clientsecrets('credentials.json', SCOPES)

Solution

  • Once you go through the Quick-Start Tutorial initially the Scope is given as:

    SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
    

    So after listing files and you decide to download, it won't work as you need to generate the the token again, so changing scope won't recreate or prompt you for the 'google authoriziation' which happens on first run.

    To force generate the token, just delete your curent token or use a new file to store your key from the storage:

    store = file.Storage('tokenWrite.json')