You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Reports SDK获取content_aware_access?寻找Reports API-ADMIN SDK接口

How to Retrieve Context-Aware Access Data via Admin SDK Reports API

Hey there! I see you're trying to pull Context-Aware Access (the content you view at audit/context_aware_access in the Admin Console) using the Admin SDK, but couldn't find the right endpoint. Let me break down exactly what you need:

1. The Correct API & SDK Path

The data you're after lives in the Admin SDK Reports API, specifically under the Context-Aware Access Audit Reports section. All official Google client libraries support this, and here's how to get set up for your language:

  • Python: Install the required packages via pip:
    pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
    
  • Java: Add this Maven dependency (or equivalent for Gradle) to your project:
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-admin-reports</artifactId>
        <version>reports_v1-rev20240304-2.0.0</version>
    </dependency>
    
  • Other languages (Node.js, Go, etc.): Look for the admin-reports client library in Google's official client library repository for your language—this is the core package you'll need.

2. Calling the Right Endpoint

To fetch the audit logs matching what you see in the Admin Console, use the activities.list method in the Reports API, and set applicationName to context_aware_access.

Here's a quick Python example to get you started:

from googleapiclient.discovery import build
from google.oauth2 import service_account

# Load your service account key (needs Domain-Wide Delegation enabled)
SCOPES = ['https://www.googleapis.com/auth/admin.reports.audit.readonly']
SERVICE_ACCOUNT_KEY = 'path/to/your-service-account-key.json'

creds = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_KEY, scopes=SCOPES)
# Delegate to your domain admin account
delegated_creds = creds.with_subject('your-admin@your-domain.com')

# Build the Reports API client
service = build('admin', 'reports_v1', credentials=delegated_creds)

# Fetch Context-Aware Access audit records
response = service.activities().list(
    userKey='all',
    applicationName='context_aware_access',
    maxResults=10
).execute()

activities = response.get('items', [])
if not activities:
    print("No Context-Aware Access activities found.")
else:
    print("Context-Aware Access Audit Logs:")
    for activity in activities:
        time = activity['id']['time']
        actor = activity['actor']['email']
        event = activity['events'][0]['name']
        print(f"{time}: {actor} performed action: {event}")

3. Quick Note on Permissions

Make sure your service account (or OAuth client) has the https://www.googleapis.com/auth/admin.reports.audit.readonly scope, and if you're using a service account, you've enabled Domain-Wide Delegation in the Admin Console for that account.

Also, if you're trying to fetch the actual Context-Aware Access security level rules (the ones you set at security/context-aware), that's a separate API: the Admin SDK Settings API's contextAwareAccessSettings endpoints (currently in Beta). You can find those in the Admin SDK documentation as well.


内容的提问来源于stack exchange,提问作者Mad-Hades

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:08:25