You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ColdFusion无客户端库调用GA4 API遇404错误求助

解决GA4 RunReport接口404错误的方案

问题根源

你的请求格式不符合GA4 API要求:runReport接口需要POST请求体直接传递JSON数据,但你用<cfhttpparam type="formfield">提交参数,会把数据编码为表单格式(application/x-www-form-urlencoded),而非接口所需的application/json格式,导致服务器无法识别请求路径,返回404。

修正后的ColdFusion代码

替换原有的formfield参数,改用type="body"直接传递JSON字符串:

<cfhttp url="https://analyticsdata.googleapis.com/v1beta/properties/XXXXX:runReport" method="post" timeout="15">
    <cfhttpparam type="header" name="Authorization" value="Bearer #access_token#">
    <cfhttpparam type="header" name="Content-type" value="application/json">
    <!-- 直接将JSON作为请求体传递,而非form字段 -->
    <cfhttpparam type="body" value="#jsonText#">
</cfhttp>

额外验证项

  • 确认XXXXX替换为你的GA4属性纯数字ID(完整路径格式为properties/123456789)
  • 检查jsonText的JSON结构是否符合规范,官方推荐驼峰式字段名:
    {"dateRanges":[{"endDate":"2023-02-20","startDate":"2023-01-01"}],"metrics":[{"name":"activeUsers"}],"dimensions":[{"name":"country"}]}
    
  • 确保access_token包含https://www.googleapis.com/auth/analytics.readonly权限范围

内容的提问来源于stack exchange,提问作者Kathryn Butterly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 18:06:39