我正在使用服务帐户访问 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();