App Insights API已废弃停止服务,如何迁移至Graph API v3.0?
迁移Facebook Graph API v2.12 App Insights代码到v3.0+
I see you're hitting that frustrating version mismatch error:
The app tried to call version v2.12. This app can only call versions v3.0 and higher, so the request defaulted to version v3.0.
The root issue is that the app_insights/app_event endpoint was deprecated starting in Graph API v3.0. Let's get your revenue-tracking code updated to use the replacement endpoint—here's how:
Key Changes to Know
- Retired Endpoint:
/{app-id}/app_insights/app_event/ - Replacement Endpoint:
/{app-id}/events - Parameter Updates: Old parameters like
aggregateByandbreakdownshave been simplified toaggregationandbreakdown
Migrated Code Example
import requests # Replace these with your actual values app_id = "YOUR_APP_ID" app_access_token = "YOUR_APP_ACCESS_TOKEN" d1 = # Your start datetime object d2 = # Your end datetime object response = requests.request( "GET", f"https://graph.facebook.com/v3.0/{app_id}/events", params={ "since": d1.strftime("%s"), "until": d2.strftime("%s"), "summary": "true", "event_name": "fb_ad_network_revenue", "aggregation": "SUM", "breakdown": "placement", "access_token": app_access_token } )
Parameter Adjustment Details
aggregateBy→aggregation: Same core function (defines how to calculate metrics, e.g.,SUM), just a streamlined parameter name.breakdowns[0]→breakdown: For a single dimension likeplacement, use this parameter directly. If you need multiple breakdowns later, separate them with commas (e.g.,breakdown=placement,platform).- API Version: Stick to v3.0 or newer (I recommend using the latest stable version, like v18.0, for the best feature support and bug fixes).
Extra Notes
- Ensure your app has the required permissions:
app_events_readorads_readdepending on your specific use case. - If you ever need more advanced revenue analytics, the Facebook Marketing API's Ads Insights endpoint is an option, but for tracking app-level ad network revenue, the
/{app-id}/eventsendpoint will work perfectly for your needs.
内容的提问来源于stack exchange,提问作者Pascal
相关产品推荐
相关产品推荐

