微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当 API 没有记录时,Google GA4 batchRunReports 抛出 500内部服务器错误

如何解决当 API 没有记录时,Google GA4 batchRunReports 抛出 500内部服务器错误

https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/TopLevel/batchRunReports

请求:

{
"entity": {
    "propertyId": "XXXXXXXX"
},"requests": [
    {
        "entity": {
            "propertyId": "XXXXXXXX"
        },"dimensions": [
            {
                "name": "date"
            },{
                "name": "dateHour"
            },{
                "name": "firstUserCampaignName"
            }
        ],"metrics": [
            {
                "name": "sessions"
            }
        ],"dateranges": [
            {
                "startDate": "2021-04-06","endDate": "2021-04-07"
            }
        ],"metricAggregations": [
            "TOTAL"
        ],"dimensionFilter": {
            "andGroup": {
                "expressions": [
                    {
                        "filter": {
                            "fieldName": "medium","stringFilter": {
                                "matchType": "EXACT","value": "Test"
                            }
                        }
                    }
                ]
            }
        },"orderBys": [
            {
                "desc": true,"metric": {
                    "metricName": "sessions"
                }
            },{
                "desc": false,"dimension": {
                    "dimensionName": "dateHour"
                }
            }
        ],"keepEmptyRows": true
    }
]

}

回复

{
"error": {
    "code": 500,"message": "Internal error encountered.","status": "INTERNAL"
}

}

但是如果从请求中删除以下属性

 "metricAggregations": [
            "TOTAL"
        ],

我可以在没有行的情况下看到以下响应:

{
"reports": [
    {
        "metricHeaders": [
            {
                "name": "sessions","type": "TYPE_INTEGER"
            }
        ],"Metadata": {},"dimensionHeaders": [
            {
                "name": "date"
            },"kind": "analyticsData#runReport"
    }
],"kind": "analyticsData#batchRunReports"

}

知道如何在这种情况下防止 500 内部服务器错误吗?

错误阻止了 Google Api 调用一个小时。

解决方法

Furqan,数据 API 似乎存在问题,如果生成的报告为空,则使用 struct ContentView: View { @State var activeView: Int = 0 @State var activeNavigationLink: Int = 0 //<-- Here let items = ["View1","View2"] func navigationLinkBinding(id: Int) -> Binding<Bool> { //<-- Here .init { () -> Bool in activeNavigationLink == id } set: { (newValue) in if newValue { activeNavigationLink = id } else { activeNavigationLink = 0 } } } var body: some View { TabView(selection: Binding<Int> ( get: { activeView },set: { activeView = $0 activeNavigationLink = 0 //<-- Here })) { NavigationView { HStack { VStack { NavigationLink( destination: Text("View 1"),isActive: navigationLinkBinding(id: 1),label: { //<-- Here Rectangle() .fill(Color.red) .cornerRadius(12) .frame(width: 70,height: 70) }).isDetailLink(false) Text(items[0]) } VStack{ NavigationLink( destination: Text("View 2"),isActive: navigationLinkBinding(id: 2),height: 70) }).isDetailLink(false) Text(items[1]) } }.navigationTitle("") .navigationBarHidden(true) } .tabItem { Image(systemName: "a.circle") Text("Main") } .tag(0) Text("View 3") .padding() .tabItem { Image(systemName: "b.circle") Text("View 3") } .tag(1) } } } 的调用将失败。同时,要解决此错误,您可以修改查询,使生成的报告包含多于 0 行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?