feat: Add get_post_metrics to all publishers for analytics
- Add abstract get_post_metrics() method to BasePublisher - Implement get_post_metrics() in XPublisher using Twitter API v2 - Returns: likes, comments, shares, retweets, quotes, impressions - Implement get_post_metrics() in ThreadsPublisher using Meta Graph API - Implement get_post_metrics() in FacebookPublisher with insights - Implement get_post_metrics() in InstagramPublisher with insights This enables the fetch_post_metrics task to collect engagement data from all platforms, populating the analytics dashboard. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -278,6 +278,36 @@ class XPublisher(BasePublisher):
|
||||
except tweepy.TweepyException:
|
||||
return False
|
||||
|
||||
async def get_post_metrics(self, post_id: str) -> Optional[Dict]:
|
||||
"""Obtener métricas de un tweet."""
|
||||
if not self.client:
|
||||
return None
|
||||
|
||||
try:
|
||||
# Obtener tweet con métricas públicas
|
||||
tweet = self.client.get_tweet(
|
||||
id=post_id,
|
||||
tweet_fields=['public_metrics', 'created_at']
|
||||
)
|
||||
|
||||
if not tweet.data:
|
||||
return None
|
||||
|
||||
metrics = tweet.data.public_metrics or {}
|
||||
|
||||
return {
|
||||
"likes": metrics.get("like_count", 0),
|
||||
"comments": metrics.get("reply_count", 0),
|
||||
"shares": metrics.get("retweet_count", 0),
|
||||
"retweets": metrics.get("retweet_count", 0),
|
||||
"quotes": metrics.get("quote_count", 0),
|
||||
"impressions": metrics.get("impression_count", 0),
|
||||
"bookmarks": metrics.get("bookmark_count", 0),
|
||||
}
|
||||
|
||||
except tweepy.TweepyException:
|
||||
return None
|
||||
|
||||
async def get_followers(self, max_results: int = 100) -> List[Dict]:
|
||||
"""Obtener lista de followers recientes."""
|
||||
if not self.client:
|
||||
|
||||
Reference in New Issue
Block a user