Very similar to this question: ValueError: Client secrets must be for a web or installed app but with a twist: I'm trying to do this through a Google Cloud Virtual Machine.
Recently, the Out-Of-Band (OOB) flow stopped working for me (it seems the reason may lie here: oob-migration. Until then, I was able to easily run the Google Sheets API on the Virtual Machine to both read/write on Google Sheet files
Now, I'm trying to follow this Python quickstart for google sheets which is almost identical to the code I already had, under the "Configure the sample"
section.
My code on Python right now is:
scopes = ['https://www.googleapis.com/auth/spreadsheets']
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', scopes)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
credentials_path, scopes)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
#Store creds in object
my_creds = creds
#Create service
build('sheets', 'v4', credentials=my_creds)
But every time Ì get this error:
ValueError: Client secrets must be for a web or installed app.
For the record, I did create the credentials under "OAuth 2.0 Client IDs"
on Google Cloud, and the application type is "Web application"
. If that's not the type, I don't know which one it should be.
Thank you so much for your help, really appreciated.