【问题标题】:sending SQL INSERT query as a parameter in POST request in FusionTable API在 FusionTable API 的 POST 请求中将 SQL INSERT 查询作为参数发送
【发布时间】:2013-02-08 09:21:38
【问题描述】:

我正在使用服务帐户访问 fusiontable API,并希望发送 POST 请求以在 fusiontable 中插入值。 我收到以下错误:

    400 Bad Request
     {
   "error": {
  "errors": [
  {
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
  "code": 400,
 "message": "Parse Error"
 }
 }

这是我的代码,请告诉我哪里出错了。

            String PostUrl = "https://www.googleapis.com/fusiontables/v1/tables";
            HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential);

            //generate the REST based URL
            GenericUrl url = new GenericUrl(PostUrl.replaceAll(" ", "%20"));
            //make POST request
            String requestBody = "sql=INSERT INTO 1DqxKZUct_VhfG3fZy6Lru1CamniDO8vv5qW6jO8 (Species) VALUES ('Red Shoes')";
            HttpRequest request = requestFactory.buildPostRequest(url, ByteArrayContent.fromString("application/json", requestBody));
            request.getHeaders().setContentType("application/json");
            request.getHeaders().set("sql", "INSERT INTO 1DqxKZUct_VhfG3fZy6Lru1CamniDO8vv5qW6jO8 (Species) VALUES ('Red Shoes')");
            System.out.println("HttpRequest request" + request);
            HttpResponse response = request.execute();
            String content = response.parseAsString();

【问题讨论】:

    标签: java post google-fusion-tables google-api-java-client google-oauth


    【解决方案1】:

    您需要将请求发送到 Google API 服务的查询端点,而不是表端点。 即将 PostUrl 值更改为

            String PostUrl = "https://www.googleapis.com/fusiontables/v1/query";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多