Meta Marketing API日期报错:近期日期触发37个月限制
错误代码3018:时间范围起始日期超出37个月限制的排查与解决
问题重现
调用Meta Marketing API的AdAccount Insights接口时,传入时间范围「11-16-23(昨日)」至「11-17-23」,收到错误提示:
The start date of the time range cannot be beyond 37 months from the current date
请求详情:
Message: Call was not successful Method: GET Path: https://graph.facebook.com/v18.0/act_********/insights Params: {'level': 'campaign', 'limit': '1000', 'time_ranges': '[{"since": "11-16-23", "until": "11-17-23"},]', 'increment': 1, 'fields': 'account_id,campaign_id,campaign_name,spend,impressions,reach,cpc,clicks,actions,conversions'}
返回响应:
Status: 400 Response: { "error": { "message": "(#3018) The start date of the time range cannot be beyond 37 months from the current date", "type": "OAuthException", "code": 3018, "fbtrace_id": "Ag-P22y80OSEXM4qsGk2T9P" } }
成因分析
核心问题是日期格式的解析歧义:
你传入的11-16-23属于MM-DD-YY格式,但Meta Marketing API对两位年份的解析逻辑会将23识别为1923年(而非预期的2023年),导致起始日期1923-11-16距离当前日期远超过37个月,触发了API的时间范围限制规则。
解决方案
直接使用**YYYY-MM-DD格式**传入日期,这是API官方推荐的无歧义格式,能确保年份被正确解析。同时注意移除time_ranges参数末尾多余的逗号,避免JSON格式错误。
修正后的time_ranges参数示例:
"time_ranges": "[{\"since\": \"2023-11-16\", \"until\": \"2023-11-17\"}]"
完整修正后的请求参数:
{'level': 'campaign', 'limit': '1000', 'time_ranges': '[{"since": "2023-11-16", "until": "2023-11-17"}]', 'increment': 1, 'fields': 'account_id,campaign_id,campaign_name,spend,impressions,reach,cpc,clicks,actions,conversions'}
内容的提问来源于stack exchange,提问作者Jeff Oberlander
相关产品推荐
相关产品推荐

