我正在尝试在服务帐户上使用域范围的委派,以从admin sdk中获取一些信息以生成报告。我有一个已经正常工作的代码库,可以与gsuite域一起使用。我想使用相同的代码为另一个域生成报告,因此我为该另一个域设置了一个GCP项目。我创建了一个服务帐户,对其启用了域范围委派,并启用了该服务帐户的范围。当我尝试模拟任何域上的任何帐户的api调用时,出现以下错误
adminService.activities().list(userKey='all', applicationName='meet').execute()
google.auth.exceptions.RefreshError: ('access_denied: Account restricted', '{\n "error": "access_denied",\n "error_description": "Account restricted",\n "error_uri":<url>}')
这是我用来创建服务的代码
credentials = service_account.Credentials.from_service_account_file(credentialsPath,
scopes=['https://www.googleapis.com/auth/admin.reports.audit.readonly',
"https://www.googleapis.com/auth/classroom.announcements.readonly",
"https://www.googleapis.com/auth/classroom.courses.readonly",
"https://www.googleapis.com/auth/classroom.coursework.students.readonly",
"https://www.googleapis.com/auth/classroom.profile.emails",
"https://www.googleapis.com/auth/classroom.rosters.readonly",
"https://www.googleapis.com/auth/classroom.student-submissions.students.readonly",
"https://www.googleapis.com/auth/classroom.topics.readonly"
])
delegated_credentials = credentials.with_subject(email)
return build('admin', 'reports_v1', credentials=delegated_credentials)
再次,这不应该是编程问题,因为相同的代码正在另一个域中工作,我认为我在admin / GCP配置端缺少了一些东西,但是我不知道是什么,而且我还没有在互联网上的任何地方都找不到此确切错误