Google Analytics API:queryCost和resourceQuotas保留在响应主体中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google Analytics API:queryCost和resourceQuotas保留在响应主体中相关的知识,希望对你有一定的参考价值。

Google Analytics API的文档中,响应正文包含queryCostresourceQuotasRemaining。但是,当我这样做时

curl -i -H 'Content-Type: application/json' -X POST 'https://analyticsreporting.googleapis.com/v4/reports:batchGet?access_token=mytoken' -d '"reportRequests":["viewId":"ga:myviewId","dateRanges":["startDate":"2019-12-04","endDate":"2019-12-04"],"dimensions":["name":"ga:campaign","name":"ga:adContent","name":"ga:keyword","name":"ga:currencyCode"],"dimensionFilterClauses":["filters":["dimensionName":"ga:sourceMedium","operator":"EXACT","expressions":["Yandex.Market / cpc"]],"filters":["dimensionName":"ga:campaign","operator":"PARTIAL","expressions":["msk"]]],"metrics":["expression":"ga:goal12Completions"],"metricFilterClauses":["filters":["metricName":"ga:goal12Completions","operator":"GREATER_THAN","comparisonValue":"0"]],"hideTotals":true,"hideValueRanges":true]'

响应主体不包含queryCostresourceQuotasRemaining

"reports":["columnHeader":"dimensions":[...],"metricHeader":"metricHeaderEntries":[...],"data":"rows":["dimensions":[...],"metrics":[...]],"rowCount":1,"isDataGolden":true]

[如果我在POST "useResourceQuotas":true中添加到JSON,则会收到错误消息:“该请求不符合资源配额。请检查帐户是否为高级帐户并将其列入白名单。” (代码400)。如何使用API​​获取有关查询成本,剩余配额和其他限额统计信息?还是只能用于高级帐户?

答案

您的请求不包含useResourceQuotas = true。其默认值为false


  "reportRequests": [
    
      "viewId": "ga:xxxx",
      "dateRanges": [
        
          "startDate": "2019-12-04",
          "endDate": "2019-12-04"
        
      ],
      "metrics": [
        
          "expression": "ga:users"
        
      ],
      "hideTotals": true,
      "hideValueRanges": true
    
  ],
  "useResourceQuotas": true

结果


  "reports": [
    
      "columnHeader": 
        "metricHeader": 
          "metricHeaderEntries": [
            
              "name": "ga:users",
              "type": "INTEGER"
            
          ]
        
      ,
      "data": 
        "rows": [
          
            "metrics": [
              
                "values": [
                  "1298"
                ]
              
            ]
          
        ],
        "rowCount": 1,
        "isDataGolden": true
      
    
  ],
  "resourceQuotasRemaining": 
    "dailyQuotaTokensRemaining": 100000,
    "hourlyQuotaTokensRemaining": 25000
  

以上是关于Google Analytics API:queryCost和resourceQuotas保留在响应主体中的主要内容,如果未能解决你的问题,请参考以下文章

Google Analytics Metadata API 识别有效组合

Google Analytics 报告 API - 权限不足 403

Google Analytics API:每个人会话导出数据

通过“google-api-php-client”库检索 Google Search Analytics

与链接到 Google Adwords 帐户的 Google Analytics API 相比,Google Adwords API 报告可以获得多少?

Google Analytics API 收入差异