google-api-python-client
を使用して、特定のユーザーから送信された電子メールのリスト(件名、日時、送信者)を取得したいとします。google-api-python-clientでG Suite Email Audit APIを使用するには?
私はG Suite Email Audit API Developer's Guideを見つけましたが、残念ながらpythonの例はありません。
google-api-python-client
でこれも可能ですか?
google-api-python-client
を使用して、特定のユーザーから送信された電子メールのリスト(件名、日時、送信者)を取得したいとします。google-api-python-clientでG Suite Email Audit APIを使用するには?
私はG Suite Email Audit API Developer's Guideを見つけましたが、残念ながらpythonの例はありません。
google-api-python-client
でこれも可能ですか?
G Suite Email Audit APIは、まだGoogle Data API protocolを使用している古いAPIの1つです。このプロトコルはgoogle-api-python-clientではサポートされていませんが、代わりにgdata-python-clientを使用する必要があります。このライブラリは古く、Googleはもうそれを更新していません。
とそれを統合する必要があります。ここでそれを使用する方法のサンプル:
from __future__ import print_function
import argparse
import gdata.apps.audit.service
from oauth2client import file, client, tools
SCOPES = ['https://apps-apis.google.com/a/feeds/compliance/audit/',]
# be sure to update with the correct user
ID = '[email protected]'
store = file.Storage('email-audit{}.json'.format(ID))
creds = store.get()
# client_id.json is the client_id file generated from the developer console project
if not creds or creds.invalid:
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
flags.auth_host_port = [8010, 8020]
flow = client.flow_from_clientsecrets('client_id.json', SCOPES)
creds = tools.run_flow(flow, store, flags)
access_token, expires_in = creds.get_access_token()
gd_client = gdata.apps.audit.service.AuditService(domain=ID.split('@')[1])
gd_client.additional_headers[u'Authorization'] = u'Bearer {0}'.format(access_token)
monitors = gd_client.getEmailMonitors(ID.split('@')[0])
print(monitors)
は、Googleから元のサンプルが必要な場合、あなたはそれをhere見つけることができます。それは私のものよりもはるかに複雑で、OAuth2認証を実行していないので動作します。参照として使用してください。