Search code examples
javagoogle-apigoogle-drive-apigoogle-oauthgoogle-api-java-client

Google Drive API giving Insufficient Permission for uploading a file


I'm trying to upload a image to google drive but it is returning 'Insufficient Permission: Request had insufficient authentication scopes.' I tried changing the scopes to DriveScopes.DRIVE_FILE, DriveScopes.DRIVE but it still throws the same error.

I'm using the sample code provided in google developer documentation

Java Quick start guide: https://developers.google.com/drive/api/v3/quickstart/java

Upload File: https://developers.google.com/drive/api/v3/manage-uploads

I enabled the drive api with desktop app option.


Solution

  • Make sure you re-authenticate the user when you changed the scope. It needs to pop up and request consent again.

    If you dont know what i am talking about. Go remove the file stored here

    .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))