사용자의 eamil 계정을 만들려면 admin sdk directory api를 사용하고 싶습니다.google admin sdk directory api 403 python
저는 google-api-python-client-1.2 라이브러리를 사용하고 있습니다.
/samples/service_account/tasks.py 폴더에 있습니다.
하지만 관리자 디렉토리에서 사용자를 나열 할 수있는 기회가있는 경우 작동하지 않으며 오류가 발생합니다.
아래 코드는 제가 사용하고있는 코드입니다.
import httplib2
import pprint
import sys
import inspect
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
def main(argv):
f = file('my-privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'[email protected]',
key,
scope=['https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.readonly'])
http = httplib2.Http()
http = credentials.authorize(http)
service = build("admin", "directory_v1", http)
list_of_apis = service.users().list(domain='mydomain.com').execute(http=http)
pprint.pprint(list_of_apis)
if __name__ == '__main__':
main(sys.argv)
위의 코드를 실행할 때 오류가 발생합니다.
$python tasks.py
No handlers could be found for logger "oauth2client.util"
Traceback (most recent call last):
File "tasks.py", line 77, in <module>
main(sys.argv)
File "tasks.py", line 66, in main
list_of_apis = service.users().list(domain='messycoders.com').execute(http=http)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 723, in execute
raise HttpError(resp, content, uri=self.uri) apiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/users?domain=messycoders.com&alt=json returned "Not Authorized to access this resource/api">
여전히 작동하지 않습니다. 동일한 오류가 발생합니다. 위의 스크립트가 내 로컬 시스템에서도 작동합니까? 아니면 등록 된 도메인에서 실행해야합니까? –
다음 사항을 확인했습니다. 1) 클라우드 콘솔의 서비스 계정 페이지에서 다운로드 한 client_secret 파일에 표시된 것처럼 서비스 계정 client_id에 messycoders.com 도메인의 Admin SDK 사용자 범위가 부여 되었습니까? 2) sub =에 사용하는 주소는 도메인의 최고 관리자입니까? –
서비스 계정은 어디에서나 작동해야합니다. –