HttpError 400错误请求-Google Admin Directory API(Python)

水星侠

我在创建Google Project即服务帐户时遇到困难。我正在Python中使用Admin SDK,尤其是Directory API。我相信我的身份验证正确,但是在调用users.list时出现以下错误:

Traceback (most recent call last):
  File "googleproject.py", line 17, in <module>
userlist = service.users().list().execute(http = http_auth)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 723, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/admin/directory/v1/users?alt=json returned "Bad Request">

我的代码如下:

from oauth2client.client import SignedJwtAssertionCredentials
from httplib2 import Http
from apiclient.discovery import build

#----AUTHORISATION----#

client_email = '*****@developer.gserviceaccount.com'
with open('*****.p12') as f:
  private_key = f.read()

credentials = SignedJwtAssertionCredentials(client_email, private_key, 'https://www.googleapis.com/auth/admin.directory.user')
http_auth = credentials.authorize(Http())

#--------------------#

service = build('admin', 'directory_v1', http = http_auth)
userlist = service.users().list().execute(http = http_auth)

我已经有和没有经过尝试它http = http_auth作为参数execute()我基本上遵循此处给出的示例:https : //code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py

我已经在开发人员控制台中启用了Admin SDK,并在Google Apps控制面板中添加了客户端ID和范围。

水星侠

我设法解决了!问题是我没有在list参数中设置域。因此,新代码如下:

from oauth2client.client import SignedJwtAssertionCredentials
from httplib2 import Http
from apiclient.discovery import build

#----AUTHORISATION----#

client_email = '*****@developer.gserviceaccount.com'
with open('*****') as f:
  private_key = f.read()

credentials = SignedJwtAssertionCredentials(client_email, private_key, 'https://www.googleapis.com/auth/admin.directory.user', sub = '[email protected]')
http_auth = credentials.authorize(Http())

#--------------------#

service = build('admin', 'directory_v1', http = http_auth)
user = service.users().list(showDeleted = False, domain = 'domain.com').execute()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

urllib2.HTTPError:HTTP错误400:错误的请求-Python

来自分类Dev

urllib.error.HTTPError:HTTP 错误 400:Python 函数中的错误请求

来自分类Dev

HTTPError:HTTP错误400:错误的请求

来自分类Dev

Google Directory API用户列表请求失败,输入400无效

来自分类Dev

Google API和Directory SDK:获取每个域的组数:HttpError(“ group”)

来自分类Dev

PY中的Google API请求错误:“ urllib.error.HTTPError:HTTP错误500:内部服务器错误”

来自分类Dev

使用Google Apps脚本中的Admin SDK Directory API创建组-错误403

来自分类Dev

重复规则错误400错误的请求-Google Api日历

来自分类Dev

Google Sheets API HttpError 500和503

来自分类Dev

Google Drive API使用PageToken返回400错误请求

来自分类Dev

使用Google Directory Admin API查找UserKey时出错

来自分类Dev

再次urllib.error.HTTPError:HTTP错误400:错误的请求

来自分类Dev

Python-使用Google Drive API时出现HttpError

来自分类Dev

向Google gmail API发出令牌请求时,请求400错误

来自分类Dev

python请求400错误

来自分类Dev

Google Calendar API忙JQuery $ .post收到400(错误请求)错误

来自分类Dev

NextPageToken给出无效的输入错误400-Google Directory API ChomeDevices

来自分类Dev

使用Google Admin SDK Directory API时获取“域无法使用api”

来自分类Dev

收到400错误的请求原因:需要来自Google Cloud stoarge json API

来自分类Dev

(400)使用Google API PHP客户端和管理SDK的错误请求

来自分类Dev

PHP:file_get_contents()HTTP / 1.0 400 Google Maps API的错误请求

来自分类Dev

使用Java中的Google Admin SDK Directory API为域创建Gmail帐户

来自分类Dev

Google Admin Directory API SDK用户上次登录不完全准确

来自分类Dev

从今天开始(2014/02/13),Google Admin SDK Directory API表现异常

来自分类Dev

使用 Google Apps 脚本从 Admin Directory API 按部门获取用户

来自分类Dev

无法将 google-api-services-admin-directory 组织转换为 JSONArray。因为缺少 customType 值

来自分类Dev

google admin sdk目录api 403 python

来自分类Dev

使用Ruby提取推文将返回“ open_http”:400错误请求(OpenURI :: HTTPError)

来自分类Dev

通过Google进行身份验证以使用Admin SDK中的Google Directory API的正确方法是什么?

Related 相关文章

  1. 1

    urllib2.HTTPError:HTTP错误400:错误的请求-Python

  2. 2

    urllib.error.HTTPError:HTTP 错误 400:Python 函数中的错误请求

  3. 3

    HTTPError:HTTP错误400:错误的请求

  4. 4

    Google Directory API用户列表请求失败,输入400无效

  5. 5

    Google API和Directory SDK:获取每个域的组数:HttpError(“ group”)

  6. 6

    PY中的Google API请求错误:“ urllib.error.HTTPError:HTTP错误500:内部服务器错误”

  7. 7

    使用Google Apps脚本中的Admin SDK Directory API创建组-错误403

  8. 8

    重复规则错误400错误的请求-Google Api日历

  9. 9

    Google Sheets API HttpError 500和503

  10. 10

    Google Drive API使用PageToken返回400错误请求

  11. 11

    使用Google Directory Admin API查找UserKey时出错

  12. 12

    再次urllib.error.HTTPError:HTTP错误400:错误的请求

  13. 13

    Python-使用Google Drive API时出现HttpError

  14. 14

    向Google gmail API发出令牌请求时,请求400错误

  15. 15

    python请求400错误

  16. 16

    Google Calendar API忙JQuery $ .post收到400(错误请求)错误

  17. 17

    NextPageToken给出无效的输入错误400-Google Directory API ChomeDevices

  18. 18

    使用Google Admin SDK Directory API时获取“域无法使用api”

  19. 19

    收到400错误的请求原因:需要来自Google Cloud stoarge json API

  20. 20

    (400)使用Google API PHP客户端和管理SDK的错误请求

  21. 21

    PHP:file_get_contents()HTTP / 1.0 400 Google Maps API的错误请求

  22. 22

    使用Java中的Google Admin SDK Directory API为域创建Gmail帐户

  23. 23

    Google Admin Directory API SDK用户上次登录不完全准确

  24. 24

    从今天开始(2014/02/13),Google Admin SDK Directory API表现异常

  25. 25

    使用 Google Apps 脚本从 Admin Directory API 按部门获取用户

  26. 26

    无法将 google-api-services-admin-directory 组织转换为 JSONArray。因为缺少 customType 值

  27. 27

    google admin sdk目录api 403 python

  28. 28

    使用Ruby提取推文将返回“ open_http”:400错误请求(OpenURI :: HTTPError)

  29. 29

    通过Google进行身份验证以使用Admin SDK中的Google Directory API的正确方法是什么?

热门标签

归档