Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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 检索位置度量时出错_Python_Json_Post_Request_Google My Business Api - Fatal编程技术网

Python 检索位置度量时出错

Python 检索位置度量时出错,python,json,post,request,google-my-business-api,Python,Json,Post,Request,Google My Business Api,我正在尝试在我的应用程序中检索位置度量。 我这样做的方式被描述 在google oauth游乐场中,它的工作很好,但当我在应用程序中执行此操作时,我的响应出现错误: { "error": { "code": 400, "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ {

我正在尝试在我的应用程序中检索位置度量。 我这样做的方式被描述 在google oauth游乐场中,它的工作很好,但当我在应用程序中执行此操作时,我的响应出现错误:

{
  "error": {
    "code": 400, 
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest", 
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"basicRequest\": Cannot bind query parameter. 'basicRequest' is a message type. Parameters can only be bound to primitive types."
          }, 
          {
            "description": "Invalid JSON payload received. Unknown name \"encodingType\": Cannot bind query parameter. Field 'encodingType' could not be found in request message."
          }
        ]
      }
    ], 
    "message": "Invalid JSON payload received. Unknown name \"basicRequest\": Cannot bind query parameter. 'basicRequest' is a message type. Parameters can only be bound to primitive types.\nInvalid JSON payload received. Unknown name \"encodingType\": Cannot bind query parameter. Field 'encodingType' could not be found in request message.", 
    "status": "INVALID_ARGUMENT"
  }
}
我的职位要求:

data = json.load(open('request.json'))
url = 'https://mybusiness.googleapis.com/v3/accounts/1054012049xxxxxxxxxx/locations:reportInsights'
        e = google.post(url=url, data=data, headers={'Content-Type': 'application/json; charset=UTF-8', "Content-Length": 291})
以及带有请求正文的json文件:

{
  "locationNames": "accounts/105401204xxxxxxxx/locations/616918704xxxxxxxxxx",
  "basicRequest": {
     "metricRequests": {
               "metric": "ALL"
     },
    "timeRange": {
      "startTime": "2017-09-02T01:01:01.045123456Z",
      "endTime": "2017-10-02T23:59:59.045123456Z"
    }
  }
}

怎么了?

负载的一个问题是“metricRequests”键是一个度量请求数组,但在您的情况下,您将其作为对象传递。修改并重新提交