Documentation Index
Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This guide walks you through setting up activity stream subscriptions to receive real-time account activity events.
PrerequisitesBefore you begin, you’ll need:
Create a subscription
Subscribe to a user’s activity events:curl -X POST "https://api.x.com/2/activity/subscriptions" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"]
}'
import requests
bearer_token = "YOUR_BEARER_TOKEN"
url = "https://api.x.com/2/activity/subscriptions"
headers = {
"Authorization": f"Bearer {bearer_token}",
"Content-Type": "application/json"
}
payload = {
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
Response:{
"data": {
"id": "1234567890",
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"],
"created_at": "2024-01-15T10:00:00.000Z"
}
}
Connect to the stream
Open a persistent connection to receive events:curl "https://api.x.com/2/activity/stream" \
-H "Authorization: Bearer $BEARER_TOKEN"
import requests
bearer_token = "YOUR_BEARER_TOKEN"
url = "https://api.x.com/2/activity/stream"
headers = {"Authorization": f"Bearer {bearer_token}"}
response = requests.get(url, headers=headers, stream=True)
for line in response.iter_lines():
if line:
print(line.decode("utf-8"))
Process incoming events
Events stream as JSON objects:{
"for_user_id": "2244994945",
"event_type": "tweet_create_events",
"created_at": "2024-01-15T10:30:00.000Z",
"tweet_create_events": [
{
"id": "1234567890",
"text": "Hello from the stream!",
"author_id": "2244994945"
}
]
}
Available event types
| Event | Description |
|---|
tweet_create_events | User posts a new Post |
favorite_events | User likes a Post |
follow_events | User follows or is followed |
direct_message_events | User sends or receives a DM |
block_events | User blocks or unblocks |
mute_events | User mutes or unmutes |
Manage subscriptions
Get all active subscriptions:curl "https://api.x.com/2/activity/subscriptions" \
-H "Authorization: Bearer $BEARER_TOKEN"
Modify event types for a subscription:curl -X PUT "https://api.x.com/2/activity/subscriptions/1234567890" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"event_types": ["tweet_create_events", "favorite_events"]
}'
Remove a subscription:curl -X DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
-H "Authorization: Bearer $BEARER_TOKEN"
Next steps
Account Activity API
Webhook-based alternative
API Reference
Full endpoint documentation