Need to track Twitter account activity for brand monitoring or competitor analysis? Here's an efficient solution using Python and the Twitter API Advanced Search endpoint.
Why This Matters
Perfect for tracking competitors' promotions
Monitor brand mentions in real-time
Track event-specific hashtags
Get alerts for crisis management
Step-by-Step Implementation
- Set Up Time Windows `from datetime import datetime, timedelta
now = datetime.now()
ten_mins_ago = now - timedelta(minutes=10)
since = int(ten_mins_ago.timestamp()) # Convert to Unix timestamp`
Configure API Request
url = "https://api.twitterapi.io/twitter/tweet/advanced_search"
headers = {"X-API-Key": "YOUR_API_KEY"}
params = {
"query": f"from:target_username since_time:{since}",
"queryType": "Latest",
"include": "nativeretweets"
}Handle Pagination
has_next_page = True
while has_next_page:
response = requests.get(url, headers=headers, params=params)
data = response.json()
tweets = data.get('tweets', [])
has_next_page = data.get('has_next_page', False)
params['cursor'] = data.get('next_cursor')
Pro Tips
- Add -filter:replies to exclude replies
- Use sleep(590) for precise 10-minute intervals
- Store results in CSV/SQLite for historical analysis
- Implement error handling for API rate limits
Why TwitterAPI.io?
The used API endpoint from twitterapi.io provides:
โ
Native retweet inclusion
โ
Precise time window filtering
โ
Pagination support
โ
High request limits
This solution helps developers build reliable Twitter monitoring tools without platform rate limit issues. The 10-minute interval ensures fresh data while maintaining API compliance.
๐ฌ Let me know what account you'd monitor with this setup! ๐
Top comments (0)