Я создал serviceaccount
в json с enabled domain-wide delegation
также Authorize
SCOPS
в приведенном ниже коде:
from googleapiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
from google.oauth2 import service_account
scopes=[
'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/admin.directory.user.readonly',
]
SERVICE_ACCOUNT_FILE = 'servie_account_file.json'
# The user we want to "impersonate"
USER_EMAIL = "superadmin@domain.com"
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=scopes)
delegated_credentials = credentials.with_subject(USER_EMAIL)
service = discovery.build('admin', 'directory_v1', credentials=credentials)
response = service.users().list(domain='domain.com').execute()
print(response)
, но получил сообщение об ошибке 403
ответ
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/users?domain=domain.com&alt=json returned "Not Authorized to access this resource/api">
ссылка Я использовал для авторизации.