首页 > 解决方案 > JSON 对象作为 BigQuery REST API 中的 GET 查询参数?

问题描述

阅读Google Cloud Platform BigQuery API https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults的文档,它指出formatOptions查询参数作为带有以下 JSON 的 JSON 对象传递结构体:

{
   "useInt64Timestamp": boolean
}

发送一个 GET 请求,例如https://bigquery.googleapis.com/bigquery/v2/projects/{{projectId}}/queries/{{JOBid}}?maxResults=1&formatOptions={"useInt64Timestamp":true}返回一个带有响应正文的 400 Bad Request:

{
"error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"formatOptions\": Cannot bind query parameter. '**formatOptions**' is a message type. Parameters can only be bound to primitive types.",
    "errors": [
        {
            "message": "Invalid JSON payload received. Unknown name \"formatOptions\": Cannot bind query parameter. 'formatOptions' is a message type. Parameters can only be bound to primitive types.",
            "reason": "invalid"
        }
    ],
    "status": "INVALID_ARGUMENT"
}

如何将formatOptions对象作为 GET 请求参数发送,如何对其进行编码以便 BigQuery API 将其识别为有效?

标签: jsonrestgoogle-cloud-platformgoogle-bigqueryget

解决方案


解决方法是发送查询参数如下:

https://bigquery.googleapis.com/bigquery/v2/projects/{{projectId}}/queries/{{jobId}?formatOptions.useInt64Timestamp=True

推荐阅读