简体   繁体   English

Google Analytics Python API “收到无效的 JSON 有效载荷。 'report_requests[0]' 中的未知名称“segment”:找不到字段。”

[英]Google Analytics Python API “Invalid JSON payload received. Unknown name ”segment“ at 'report_requests[0]': Cannot find field.”

I followed the Google Analytics (GA) Hello Analytics tutorial and used the query explorer to call the GA API via Python and this worked great until I tried to include a segment in my query.我遵循了 Google Analytics (GA) Hello Analytics 教程,并使用查询资源管理器通过 Python 调用 GA API,这非常有效,直到我尝试在查询中包含一个段。 It seems that the query explorer's use of segments (or my understanding of how to use this) is not correct.似乎查询资源管理器对段的使用(或我对如何使用它的理解)不正确。 Here is my get_report function:这是我的 get_report function:

def get_report(analytics, segment):
if segment == "all":
    bdy = {
        'reportRequests': [
            {
                'viewId': VIEW_ID,
                'dateRanges': [{'startDate': '2021-01-19', 'endDate': 'yesterday'}],
                'metrics': [{'expression': 'ga:uniqueEvents'}],
                'dimensions': [{'name': 'ga:eventLabel'}]
            }]
    }
elif segment == "internal":
    bdy = {
        'reportRequests': [
            {
                'viewId': VIEW_ID,
                'dateRanges': [{'startDate': '2021-01-19', 'endDate': 'yesterday'}],
                'metrics': [{'expression': 'ga:uniqueEvents'}],
                'dimensions': [{'name': 'ga:eventLabel'}],
                "segment": "gaid::aqYF4QvFTX6JhLKfs0R84A"
            }]
    }

return analytics.reports().batchGet(body=bdy).execute()

The first if block works perfectly fine but when I try to run the second I get this error:第一个 if 块工作得很好,但是当我尝试运行第二个时,我得到了这个错误:

HttpError: <HttpError 400 when requesting https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "Invalid JSON payload received. Unknown name "segment" at 'report_requests[0]': Cannot find field." HttpError:<HttpError 400 在请求https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json时返回“无效 JSON 有效负载收到。在'report 中找不到未知名称“report_”。 " . . Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'report_requests[0]', 'description': 'Invalid JSON payload received. Unknown name "ga:segment" at 'report_requests[0]': Cannot find field.'}]}]">详细信息:“[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'report_requests[0]', 'description': '收到无效的 JSON 有效载荷. 'report_requests[0]' 中的未知名称“ga:segment”:找不到字段。'}]}]">

It seems like the "segment" key in the second body dictionary is not correct, but I can't find what it should be.似乎第二个正文字典中的“段”键不正确,但我找不到它应该是什么。 Does anyone know how to correct this?有谁知道如何纠正这个?

In case this is helpful, this is what the query explorer suggested I use:如果这有帮助,这是查询资源管理器建议我使用的:

"query": {
"start-date": "2021-01-19",
"end-date": "yesterday",
"ids": "ga:xxxxxxxx",
"dimensions": "ga:eventCategory,ga:eventLabel",
"metrics": [
  "ga:uniqueEvents"
],
"segment": "gaid::aqYF4QvFTX6JhLKfs0R84A",
"start-index": 1,
"max-results": 1000

} }

I think the query explorer might use v3 of the API, while I'm using v4....我认为查询资源管理器可能使用 API 的 v3,而我使用的是 v4....

Thanks in advance!提前致谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Play 控制台 API 返回“收到的 JSON 有效负载无效。 \'track_config\' 中的未知名称“versionCodes”:找不到字段。 - Google Play Console API return 'Invalid JSON payload received. Unknown name “versionCodes” at \'track_config\': Cannot find field.' GoogleSheets API:“收到无效的 JSON 有效负载。‘data.values[0]’处的未知名称“数字”:找不到字段 - GoogleSheets API:"Invalid JSON payload received. Unknown name "Number" at 'data.values[0]': Cannot find field Google Sheets API BatchUpdate InsertRange返回“收到无效的JSON有效负载。 Python 3.6中的“未知名称” - Google Sheets API BatchUpdate InsertRange returns “Invalid JSON payload received. Unknown name” in Python 3.6 Google Cloud - 收到无效的 JSON 负载。 “配置”中的未知名称“编码”:原型字段不重复,无法启动列表 - Google Cloud - Invalid JSON payload received. Unknown name "encoding" at 'config': Proto field is not repeating, cannot start list python中的Google People API给出错误:接收到无效的JSON有效负载。 未知名称“”:根元素必须是一条消息。 - Google People API in python gives error: Invalid JSON payload received. Unknown name “”: Root element must be a message." “收到无效的 JSON 有效载荷。 在 Python 中使用 Google Sheet APIv4 batchUpdate() 时,“data[0]”处的未知名称“range” - “Invalid JSON payload received. Unknown name ”range“ at 'data[0]'” when using Google Sheet APIv4 batchUpdate() in Python 将数据框上传到Google BigQuery。 接收到无效的JSON有效负载。 意外的标记 - Uploading dataframe to Google BigQuery. Invalid JSON payload received. Unexpected token Google API版本2上的API.ai操作:无法解析带有“ INVALID_ARGUMENT”错误的JSON响应字符串:“:找不到字段。” - API.ai Actions on Google API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: “: Cannot find field.” python API启动模板未知名称找不到字段 - python api to launch template unknown name cannot find field 收到错误 {{&#39;code&#39;: 400, &#39;message&#39;: &#39;收到无效的 JSON 有效负载。 意外的令牌。\ncomment=谢谢+你\n^&#39;, &#39;status&#39;: &#39;INVALID_ARGUMENT&#39;}} - Getting error {{'code': 400, 'message': 'Invalid JSON payload received. Unexpected token.\ncomment=Thank+you\n^', 'status': 'INVALID_ARGUMENT'}}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM