I wrote a Python script(Google_add.py) which creates users in the Google Workspace. However, When it is run, an AttributeError occurred. How do I resolve this Error?
・Google_add.py (Excerpt)
PATH = '/opt/Google/credentials.json'
CLIENT_SECRETS = '/opt/Google/client_secrets.json'
credentials = None
#If there are credentials
if os.path.exists(PATH):
credentials = Credentials.from_authorized_user_file(
path = PATH,
scopes = SCOPES)
#If there are no (valid) credentials available
if not credentials or not credentials.valid:
if credentials and credentials.expired and credentials.refresh_token:
credentials.refresh(Request())
else:
FLOW = flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file = CLIENT_SECRETS,
scopes = SCOPES)
credentials = FLOW.run_console()
with open(PATH, 'w') as token:
token.write(credentials.to_json())
・Error Message
File "Google_add.py", line 186, in <module>
main()
File "Google_add.py", line 172, in main
FLOW.run_console()
AttributeError: 'InstalledAppFlow' object has no attribute 'run_console'
I refer the below site when I wrote it. https://github.com/googleapis/google-api-python-client/blob/main/docs/oauth-installed.md#sending-users-to-googles-oauth-20-server https://developers.google.com/admin-sdk/directory/v1/quickstart/python?hl=en
In the script, I want to authorize using the user account(not service account). And "run_local_server()" method doesn't work because my linux server isn't a web server (doesn't have httpd, nginx and so on).
(I'm sorry if my writing is hard to read.)