没有ClientLogin的gdata.apps.audit.service身份验证

时间:2014-10-20 18:00:25

标签: python oauth-2.0 gmail google-admin-sdk google-admin-audit-api

我想利用gdata.apps.audit.service.AuditService来创建邮箱导出请求(特别是通过createMailboxExportRequest)。是否可以通过oauth或其他方式访问此api身份验证?我试图避免要求用户提供用户名和密码。

以下是一段代码示例:

audit_service = gdata.apps.audit.service.AuditService(domain="test.com")

#would like to not use ClientLogin
client = audit_service.ClientLogin("adm_user@test.com", "superSecretPassword") # <------
audit_service.createMailboxExportRequest(user="target_user", begin_date=None, end_date=None,     include_deleted=True, search_query=None)
audit_service.getAllMailboxExportRequestsStatus()

我成功地将oauth2 / client_secrets用于其他管理/审核API,但我无法弄清楚如何在没有ClientLogin的情况下获取createMailboxExportRequest。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

我发现将OAuth 2.0入侵旧GData API的最简单方法是构建GData服务(但不授权它),然后构建一个凭据服务,就像您对新的OAuth 2.0发现Google API一样,然后在GData服务上添加适当的凭据作为标题:

audit_service = gdata.apps.audit.service.AuditService(domain="test.com")
...   # build your credentials like normal with oauth2client
auth_headers = {u'Authorization': u'Bearer %s' % credentials.access_token}
audit_service.additional_headers = auth_headers