구글 API 사용
의 목적
Google API 설명과 서비스 계정 등을 생략하면
문서를 읽고 썼으니 문서를 읽으세요.
이 기사는 GoogleWorkSpace의 특정 사용자를 구성원으로 하는 Group을 일람화하는 방법에 대해 설명합니다.
올가미일
문서대로 GCP에서 프로젝트를 시작하고 서비스 계정을 만들고 키(JSON)를 다운로드해 코드를 실행했지만 제대로 진행되지 않아 인정받지 못한 오류가 없어 고민했다.
message': 'Not Authorized to access this resource/api
결론GoogleWorkSpace 관리에 역할이 할당되지 않았기 때문입니다.
캐릭터를 만들었는데 이번에는 그룹 조작을 했기 때문에 팀에 권한(검사)만 부여하고 서비스 계정에 분배하여 해결합니다.
샘플 코드
qiita.py
#Googleクライアントライブラリ
from googleapiclient.discovery import build
from google.oauth2.service_account import Credentials
SECRETS = '[秘密鍵].json'
SCOPES = ['https://www.googleapis.com/auth/admin.directory.group']
def Get_GoogleGroup():
#クレデンシャルインスタンスの作成
credentials = Credentials.from_service_account_file(SECRETS)
#スコープの追加
scoped_credentials = credentials.with_scopes(SCOPES)
service = build('admin', 'directory_v1', credentials=scoped_credentials)
results = service.groups().list(domain='hoge.com', userKey='[email protected]').execute()
results = results['groups']
groups = []
for i in range(len(results)):
groups.append(results[i]['email'])
print(groups)
Reference
이 문제에 관하여(구글 API 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ranmatsu/items/a10bf263d0f19872bafa텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)