1

I am simply trying to create a new folder on google drive using the Google Drive API.

I have created a Service Account as well as a OAuth 2.0 Client IDs (and have downloaded their respective client secret .json files) for a project in which the Drive API has been enabled.

However, I am still encountering endless problems. The template example below has not worked for me (nor have any other solutions to people encountering the same problem).

file_metadata = {
    'name': 'Invoices',
    'mimeType': 'application/vnd.google-apps.folder'
}
file = drive_service.files().create(body=file_metadata,
                                    fields='id').execute()
print 'Folder ID: %s' % file.get('id')

If I am using:

SCOPE = ['https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name(CLIENT_SECRET_FILE, SCOPE)

then plugging in the .json downloaded from the Service Account for CLIENT_SECRET_FILE, I get the error Client secrets must be for a web or installed app

If I instead try to authenticate CLIENT_SECRET_FILE with a key json file generated via OAuth2 credentials I get and Authorization Error

Error 400: redirect_uri_mismatch
The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client... 

I have also created an API Key for the project. Is there an easier way to achieve this by using the API Key, as opposed to the .json files?

Any help would be much appreciated.

ZwiTrader
  • 195
  • 1
  • 2
  • 12
  • How are you creating the authorization part? Have you checked this answer [here](https://stackoverflow.com/a/64509140/11772035)? – ale13 Jun 24 '21 at 13:49
  • Yes, I tried that solution which also failed. I stubbornly kept adding the denied redirect URIs to my list of authorized redirects and after adding the 5th it all started magically working. Not sure why nor how long it will last... – ZwiTrader Jun 24 '21 at 16:49
  • Would you mind posting it as an answer (for documentation purposes)? – ale13 Jun 25 '21 at 10:03

1 Answers1

0

You should add the redirect URIs needed into the list.

ale13
  • 5,679
  • 3
  • 10
  • 25