-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_start.py
More file actions
87 lines (69 loc) · 2.69 KB
/
quick_start.py
File metadata and controls
87 lines (69 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""
Trillboards Partner API - Python Quick Start
This example demonstrates the 3-step integration:
1. Get VAST configuration (cache for 1 hour)
2. Fetch VAST from Google Ad Manager (Trillboards not in critical path)
3. Report impressions after ad completion
Usage:
TRILLBOARDS_API_KEY=trb_partner_xxx python quick_start.py
"""
import os
import sys
from datetime import datetime
try:
import requests
except ImportError:
print("Error: Install requests library: pip install requests")
sys.exit(1)
TRILLBOARDS_API = os.environ.get('TRILLBOARDS_API_URL', 'https://api.trillboards.com')
API_KEY = os.environ.get('TRILLBOARDS_API_KEY')
if not API_KEY:
print('Error: Set TRILLBOARDS_API_KEY environment variable')
sys.exit(1)
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
def main():
# Step 1: Get VAST configuration (cache this for 1 hour)
print('1. Fetching VAST configuration...')
config_response = requests.get(
f'{TRILLBOARDS_API}/v1/partner/vast/config',
headers=headers
)
config = config_response.json()
if not config.get('success'):
raise Exception(f"Config failed: {config.get('message')}")
print(f" VAST tag URL: {config['data']['vast_tag_template']}")
print(f" Fill rate: {config['data'].get('estimated_fill_rate', 'N/A')}")
# Step 2: In production, your player fetches VAST directly from Google
# This keeps Trillboards out of the critical ad serving path
vast_url = config['data']['vast_tag_template'] \
.replace('[DEVICE_ID]', 'demo-device-001') \
.replace('[TIMESTAMP]', str(int(datetime.now().timestamp() * 1000)))
print(f'\n2. Your player would fetch VAST from: {vast_url}')
print(' (Google IMA SDK handles this automatically)')
# Step 3: After ad completes, report the impression
print('\n3. Reporting impression after ad completion...')
tracking_response = requests.post(
f'{TRILLBOARDS_API}/v1/partner/tracking/batch',
headers=headers,
json={
'impressions': [{
'device_id': 'demo-device-001',
'ad_id': 'ima_demo_ad_123',
'event': 'complete',
'timestamp': datetime.utcnow().isoformat() + 'Z',
'duration_ms': 15000
}]
}
)
result = tracking_response.json()
processed = result.get('data', {}).get('processed', 0)
proofs = len(result.get('data', {}).get('proofs', []))
print(f' Processed: {processed}')
print(f' Proofs: {proofs} Ed25519 signatures')
print('\nIntegration complete! Your screens are now monetized.')
if __name__ == '__main__':
main()