2017-10-11 68 views
-1

我正试图在我的应用中检索位置指标。 我做的方式描述here. 在谷歌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" 
    } 
} 

我交requst:

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" 
    } 
    } 
} 

有什么不好?

回答

0

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