Harry Lau
Harry Lau

Reputation: 31

google admin api - client_secrets error

I was playing around with google admin api and put the example code together with a little modification. I set things up correctly on the google end, but when I run the script it kept giving me errors. Below is my code in python:

from __future__ import print_function

from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools

SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store)
SERVICE = build('admin', 'directory_v1', http=creds.authorize(Http()))


results = SERVICE.users().list(customer='my_customer', maxResults=10,
    orderBy='email').execute()
users = results.get('users', [])

Error I am getting is this:

Traceback (most recent call last):
  File "quickstart.py", line 11, in <module>
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
  File "build/bdist.macosx-10.12-intel/egg/oauth2client/_helpers.py", line 133, in positional_wrapper
  File "build/bdist.macosx-10.12-intel/egg/oauth2client/client.py", line 2125, in flow_from_clientsecrets
  File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 165, in loadfile
  File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 126, in _loadfile
  File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 101, in _validate_clientsecrets
oauth2client.clientsecrets.InvalidClientSecretsError: Missing property "client_secret" in a client type of "installed".

I am new to google api and would very much appreciate for any helps.

Thanks

Upvotes: 3

Views: 1214

Answers (3)

Addin Cui
Addin Cui

Reputation: 83

You need to click RESET SECRET button in the JSON Download page. enter image description here

After that, you will have a brand new Client Secret and auto generated in your Json file.

enter image description here

I just encountered this same exact problem, and solved it this way. Hope it helps.

Upvotes: 1

Zack Maldonado
Zack Maldonado

Reputation: 56

The issue I've found is with the name of Google's OAuth 2.0 client IDs. For your client ID, the name must EXACTLY be Google Sheets API Quickstart, or else the "client_secret" won't be populated in the client_secret.json when you download it from Google.

Alternatively, you could manually add a property under the installed JSON object, such as "client_secret":"mysupercoolsecret", using the secret generated for the credential when you made the credential.

Either way, I have no idea why Google would only populate the "client_secret" field when the name of the credential doesn't match a certain value.

Hope this helps. I've encounter this issue with using the Google API for other languages as well.

Upvotes: 1

Nishant Nikhil
Nishant Nikhil

Reputation: 1

Download the client_secret.json again. There is a problem with that file.

You can use this link for a small tutorial to get your client_secret.

Upvotes: -1

Related Questions