chore(performance): 메타 insights 원본 응답 확인 스크립트(진단, 읽기 전용)
지출·노출·클릭만 0 으로 들어오는 원인 확인용 — 저장된 인증정보로 하루치를 조회해 원본 JSON(토큰 가림)을 출력. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""메타 광고 insights 원본 응답 확인(진단, 읽기 전용) — 실적 설정에 저장된 메타 인증정보로 하루치를 조회해 원본 JSON 을 보여 준다.
|
||||
|
||||
2026-10-21: 광고비 탭 메타 일자별 보고서에서 구매수·링크 클릭·구매 전환값은 들어오는데 지출 금액·노출수·클릭수만 0 →
|
||||
메타가 그 칸을 어떤 모양으로 보내는지 원본을 보려고 만듦. DB·메타 설정은 바꾸지 않는다(GET 만). 토큰·appsecret_proof 는 출력하지 않는다.
|
||||
|
||||
운영 서버(웹 컨테이너 dbx-main 안에서, 호스트의 이 파일을 stdin 으로 넘긴다 — 이미지 다시 빌드 불필요):
|
||||
cd /opt/www/main && git pull && docker exec -i dbx-main python - 2026-10-20 < scripts/meta_insights_raw.py
|
||||
날짜를 빼면 어제(KST).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from datetime import date, timedelta
|
||||
|
||||
import httpx
|
||||
|
||||
from app.modules.performance.ad_sources.meta_ads import API_BASE, INSIGHT_FIELDS, MetaAdsSource
|
||||
from app.modules.performance.ad_sync import AdSyncService, ad_credentials
|
||||
from app.modules.performance.common import key_ring
|
||||
from app.modules.performance.db import PerformanceDBStore
|
||||
from app.timezone import today_kst
|
||||
|
||||
|
||||
def _redact(obj: object, secrets: list[str]) -> object:
|
||||
text = json.dumps(obj, ensure_ascii=False, indent=2)
|
||||
for s in secrets:
|
||||
if s:
|
||||
text = text.replace(s, "***")
|
||||
return re.sub(r"(access_token|appsecret_proof)=[^&\"\s]+", r"\1=***", text)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
day = date.fromisoformat(sys.argv[1]) if len(sys.argv) > 1 else today_kst() - timedelta(days=1)
|
||||
store = PerformanceDBStore(os.environ["PERFORMANCE_DB_URL"])
|
||||
sync = AdSyncService(store, ad_credentials(store, key_ring))
|
||||
ctx = sync._ctx("meta")
|
||||
src = MetaAdsSource()
|
||||
accounts, version, auth = src._setup(ctx)
|
||||
secrets = [v for v in auth.values() if v]
|
||||
tr = json.dumps({"since": day.isoformat(), "until": day.isoformat()})
|
||||
print(f"# 메타 insights 원본 — {day} · API {version} · 계정 {len(accounts)}개")
|
||||
with httpx.Client(timeout=30.0) as client:
|
||||
for acc in accounts:
|
||||
url = f"{API_BASE}/{version}/act_{acc}/insights"
|
||||
for label, fields in (("앱이 쓰는 요청", INSIGHT_FIELDS), ("지출·노출·클릭만", "spend,impressions,clicks,account_currency")):
|
||||
resp = client.get(url, params={**auth, "level": "account", "time_increment": 1, "fields": fields, "time_range": tr})
|
||||
try:
|
||||
body: object = resp.json()
|
||||
except ValueError:
|
||||
body = resp.text[:2000]
|
||||
print(f"\n## act_{acc} · {label} · HTTP {resp.status_code}")
|
||||
print(_redact(body, secrets))
|
||||
store.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user