Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将过滤器应用于Google Analytics API_Python_Google Analytics Firebase - Fatal编程技术网

在python中将过滤器应用于Google Analytics API

在python中将过滤器应用于Google Analytics API,python,google-analytics-firebase,Python,Google Analytics Firebase,我对谷歌分析(Google analytics)写查询是个新手,我对在下面的方法中添加一个过滤器很感兴趣。具体地说,是为了过滤出位置,但只要操作员字段中出现“精确”以外的内容,我就会不断收到错误。用于尺寸过滤器 是否有该字段的有效运算符列表?”“不精确”,“不等于”,符号也不精确!=,=/=。他们似乎出错了。具体错误为:请求时400https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json 返回“report_re

我对谷歌分析(Google analytics)写查询是个新手,我对在下面的方法中添加一个过滤器很感兴趣。具体地说,是为了过滤出位置,但只要操作员字段中出现“精确”以外的内容,我就会不断收到错误。用于尺寸过滤器

是否有该字段的有效运算符列表?”“不精确”,“不等于”,符号也不精确!=,=/=。他们似乎出错了。具体错误为:请求时
400https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json 返回“report_requests[0]处的值无效。维度_filter_子句[0]。筛选器[0]。运算符(类型_ENUM),“NOT_EQUAL”“>
,因此似乎必须有可接受运算符的枚举,我就是找不到它

def get_report(analytics):
'''Use the Analytics Service Object to query the Analytics Reporting API V4.'''
return analytics.reports().batchGet(
  body={
    'reportRequests': [
    {
      'viewId': VIEW_ID,
      'dateRanges': [{'startDate': '2016-07-01', 'endDate': 'today'}],
      'metrics': [{'expression': 'ga:pageviews'}],
      'dimensions': [{'name': 'ga:country'}, {'name': 'ga:city'}],
      'metricFilterClauses': [{
      'filters': [{
          "metricName": "ga:pageviews",
          "operator": "GREATER_THAN",
          "comparisonValue": "1000"
      }]
      }],
      'dimensionFilterClauses': [
        {
          'filters': [
            {
              "dimensionName": "ga:country",
              "operator": "EXACT",
              "expressions": ["United States"]
            }
          ]
        }
      ]
    }]
  }
).execute()

从这里看来:

…这导致:

它应该是
。不确定为什么会出现
EXACT
——似乎只是API文档中没有正式的东西。如果未指定,则将其视为“或”。

也许这对您有所帮助

     def get_report(analytics):
'''Use the Analytics Service Object to query the Analytics Reporting API V4.'''
return analytics.reports().batchGet(
  body={
    'reportRequests': [
    {
      'viewId': VIEW_ID,
      'dateRanges': [{'startDate': '2019-07-01', 'endDate': '2020-04-01'}],
      'metrics': [{'expression': 'ga:pageviews'}],
      'dimensions': [{'name': 'ga:country'}, {'name': 'ga:city'}],
      "dimensionFilterClauses":[
        {
           "operator":"AND",
           "filters":[
              {
                 "dimensionName":"ga:pageviews",
                 "operator":"NUMERIC_GREATER_THAN",
                 "expressions":[
                    1000
                 ]
              },
              {
                "dimensionName":"ga:country",
                "operator":"EXACT",
                "expressions":[
                   "United States"
                ]
             }
           ]
        }
     ],
    }]
  }
).execute()

尝试提供解释和代码片段