0
我一直在尝试使用Python和服务帐户访问新的Reports API以下载用户登录信息。我可以成功构建一个服务帐户,然后尝试使用ApplicationName ='login'来调用activities.list(请参阅下面的代码片段)。Python API客户端无法识别Reports API的登录类型
def createAuditService():
f = file(my-private-key, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(my-service-account, key,
scope='https://www.googleapis.com/auth/admin.reports.audit.readonly')
http = httplib2.Http()
http = credentials.authorize(http)
return build('reports', 'v1', http=http)
def retrieveActivites(service):
try:
Logins = service.activities().list(userKey='all',applicationName='login').execute()
return Logins.get('items',[])
except errors.HttpError, error:
log.error('An error occurred.',exc_info=True)
return None
def main():
service = createAuditService()
activities = retrieveActivites(service)
print activities
相反,我得到以下错误:
2013-11-28 09:51:17,727 - apiclient.discovery - INFO - URL being requested: https://www.googleapis.com/discovery/v1/apis/reports/v1/rest
2013-11-28 09:51:17,727 - oauth2client.client - INFO - Attempting refresh to obtain initial access_token
2013-11-28 09:51:18,135 - oauth2client.client - INFO - Refreshing access_token
Traceback (most recent call last):
File "F:\Dropbox\code\glogin-audit\glogin.py", line 105, in <module>
main()
File "F:\Dropbox\code\glogin-audit\glogin.py", line 91, in main
activities = retrieveActivites(service)
File "F:\Dropbox\code\glogin-audit\glogin.py", line 75, in retrieveActivites
Logins = service.activities().list(userKey='all',applicationName='login').execute()
File "build\bdist.win32\egg\apiclient\discovery.py", line 595, in method
(name, pvalue, regex))
TypeError: Parameter "applicationName" value "login" does not match the pattern "(admin)|(docs)"
使用“管理员”或“文档”值,而不是针对的applicationName参数“登录”产生有效的数据,所以我相当肯定我具有正确的语法(请参阅API参考here以及Python客户端参考here)。
而且,我有使用Python客户端1.1版的问题,但我有同样的问题后,我升级到1.2:easy_install --upgrade google-api-python-client
任何建议的下一步?