如何解决当 API 没有记录时,Google GA4 batchRunReports 抛出 500内部服务器错误
请求:
{
"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"
}
此错误阻止了 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 举报,一经查实,本站将立刻删除。