2015-04-10 3 views
0

Я пытаюсь получить список пользователей из Google с помощью google_api_python_client-1.4.0. Я получаю ошибку access_denied, даже если у меня есть полномочия делегирования домена.Использование API Google API Python с SignedJwtAssertionCredentials

Интересно, что .. когда я использую тот же сертификат/учетные данные с .net-клиентской библиотекой, он работает.

Ошибка я получаю Файл "/Library/Python/2.7/site-packages/oauth2client-1.4.6-py2.7.egg/oauth2client/client.py", строка 807, в _do_refresh_request oauth2client.client.AccessTokenRefreshError: access_denied: запрашиваемый клиент не авторизован.

# Load the key in PKCS 12 format that you downloaded from the Google API 
# Console when you created your Service account. 
f = file('Gkeys/87ty8g87-privatekey.p12', 'rb') 
key = f.read() 
f.close() 
# Create an httplib2.Http object to handle our HTTP requests and authorize it 
# with the Credentials. Note that the first parameter, service_account_name, 
# is the Email address created for the Service account. It must be the email 
# address associated with the key that was created. 
credentials = SignedJwtAssertionCredentials(
    '[email protected]', 
    key, 
    scope=['https://www.googleapis.com/auth/admin.directory.group.readonly','https://www.googleapis.com/auth/admin.directory.user.readonly'], 
    private_key_password='notasecret', 
    sub='[email protected]' 

) 


http = httplib2.Http() 
http = credentials.authorize(http) 


directory_service = build('admin', 'directory_v1', http=http) 

all_users = [] 
page_token = None 

params = {'groupKey': '[email protected]'} 

while True: 
    try: 
    if page_token: 
     params['pageToken'] = page_token 
    #current_page = directory_service.users().list(**params).execute() 
    #current_page = directory_service.members().list(**params).execute() 
    current_page = directory_service.members().list(groupKey='[email protected]ain.com').execute() 

    all_users.extend(current_page['users']) 
    page_token = current_page.get('nextPageToken') 
    if not page_token: 
     break 
    except errors.HttpError as error: 
    print 'An error occurred: %s' % error 
    break 

for user in all_users: 
    print user['primaryEmail'] 

ответ

1

Вы уверены, что прицелы вы уполномоченные на панели управления точно соответствуют Вы запрашиваете здесь? Если вы разрешили область чтения/записи и используете область readonly, я считаю, что это приведет к вашей ошибке.

+0

Спасибо, Джей! Вот и все. Я не знал, что область должна точно соответствовать. – ZOO

Смежные вопросы