2016-09-06 5 views
1

그룹의 모든 구성원을 검색하려고하는데 오류가 발생합니다. 여기Python Google Admin SDK 403 오류

# -*- coding: utf-8 -*- 

from __future__ import print_function 
import httplib2 
import os 

from apiclient import discovery 
import oauth2client 
from oauth2client import client 
from oauth2client import tools 

try: 
    import argparse 
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() 
except ImportError: 
    flags = None 

# If modifying these scopes, delete your previously saved credentials 
# at ~/.credentials/admin-directory_v1-python-quickstart.json 
SCOPES = 'https://www.googleapis.com/auth/admin.directory.group.member.readonly' 
CLIENT_SECRET_FILE = 'client_secret.json' 
CRED_SAVE = 'cred_save.json' 
APPLICATION_NAME = 'Directory API Python Quickstart' 


def get_credentials(): 
    """Gets valid user credentials from storage. 

    If nothing has been stored, or if the stored credentials are invalid, 
    the OAuth2 flow is completed to obtain the new credentials. 

    Returns: 
     Credentials, the obtained credential. 
    """ 
    home_dir = os.path.expanduser('~') 
    credential_dir = os.path.join(home_dir, '.credentials') 
    if not os.path.exists(credential_dir): 
     os.makedirs(credential_dir) 
    credential_path = os.path.join(credential_dir, 
            CRED_SAVE) 

    store = oauth2client.file.Storage(credential_path) 
    credentials = store.get() 
    if not credentials or credentials.invalid: 
     flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) 
     flow.user_agent = APPLICATION_NAME 
     if flags: 
      credentials = tools.run_flow(flow, store, flags) 
     else: # Needed only for compatibility with Python 2.6 
      credentials = tools.run(flow, store) 
     print('Storing credentials to ' + credential_path) 
    return credentials 

def get_remote_users(service, http, group="[email protected]"): 
    request = service.members().list(groupKey=group).execute() 


def main(): 
    """Shows basic usage of the Google Admin SDK Directory API. 

    Creates a Google Admin SDK API service object and outputs a list of first 
    10 users in the domain. 
    """ 

    credentials = get_credentials() 
    http = credentials.authorize(httplib2.Http()) 
    service = discovery.build('admin', 'directory_v1', http=http) 

    users = get_remote_users(service, http) 

    if not users: 
     print('No users in the domain.') 
    else: 
     print('Users:') 
     for user in users: 
      print('{0} ({1})'.format(user['primaryEmail'], 
       user['name']['fullName'])) 


if __name__ == '__main__': 
    main() 

오류입니다 : 여기

내 코드입니다 나는 403 오류를 받고 있어요 왜

Traceback (most recent call last): 
    File "/Users/user/Documents/workspace/module/groups_members.py", line 84, in <module> 
    main() 
    File "/Users/user/Documents/workspace/module/groups_members.py", line 72, in main 
    users = get_remote_users(service, http) 
    File "/Users/user/Documents/workspace/module/groups_members.py", line 58, in get_remote_users 
    request = service.members().list(groupKey=group).execute() 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper 
    return wrapped(*args, **kwargs) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/googleapiclient/http.py", line 832, in execute 
    raise HttpError(resp, content, uri=self.uri) 
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/groups/all.faculty%40myorg.jp/members?alt=json returned "Insufficient Permission"> 

어떤 생각? 지금까지 내가 알고있는 한 올바른 범위에 있고 올바른 json 인증 파일을 저장했습니다. 이 코드로 사용자를 나열하고 403 오류를받지 않는 것과 같은 다른 작업도 수행 할 수 있습니다.

아마도 내가해야 할 추가 인증이 있습니다.

도움을 주시면 감사하겠습니다.

건배

답변

0

분명히 읽을 수 없습니다.

~/.credentials/

에서 자격 증명을 삭제하여 해결했습니다.
관련 문제