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:
2026-02-03 22:12:54 +00:00
parent 9008c5d945
commit 67263e7ed9
5 changed files with 164 additions and 0 deletions

View File

@@ -225,3 +225,31 @@ class ThreadsPublisher(BasePublisher):
"""Eliminar un post de Threads (no soportado actualmente)."""
# La API de Threads no soporta eliminación actualmente
return False
async def get_post_metrics(self, post_id: str) -> Optional[Dict]:
"""Obtener métricas de un post de Threads."""
if not self.access_token:
return None
try:
async with httpx.AsyncClient() as client:
url = f"{self.base_url}/{post_id}"
params = {
"fields": "id,likes,replies,quotes,reposts",
"access_token": self.access_token
}
response = await client.get(url, params=params)
response.raise_for_status()
data = response.json()
return {
"likes": data.get("likes", 0),
"comments": data.get("replies", 0),
"shares": data.get("reposts", 0),
"quotes": data.get("quotes", 0),
"impressions": 0, # No disponible en API pública
}
except httpx.HTTPError:
return None