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
任何建議的下一步?