我正在尝试将查询传递给电子表格。我有一个价值说“John cena”。如何在以下行中传递它。我这样做时出错了
ListQuery query = new ListQuery(listFeedUrl);
query.setSpreadsheetQuery("name = 'John cena' and age > 25");
ListFeed feed = service.query(query, ListFeed.class);
这是我得到的错误:
com.google.gdata.util.InvalidEntryException: Bad Request
Parse error: Invalid token encountered
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
at com.google.gdata.client.Service.query(Service.java:1237)
at com.google.gdata.client.Service.query(Service.java:1178)
答案 0 :(得分:3)
对不起,我完全不知道答案,但我想提供帮助。
你可以尝试这样的事情:
query.setSpreadsheetQuery("name = \"John cena\" and age > 25");
wiki帖子@ http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#SendingStructuredRowQueries表示您必须在引号中包含空格数据。
答案 1 :(得分:0)
我遇到了同样的问题,我的项目列的值可能包含空格。通过添加双引号并将其转换为字符串,我能够绕过这个问题。此外,您可能希望删除查询中的其他空格,除了“和”之间的空格,以防万一。
String queryString = ""; //should contain feedURL
ListQuery lsListQuery = new ListQuery(new URI(queryString).toURL());
lsListQuery.setSpreadsheetQuery("item=\"Item Name4\" ");
\\This will have the URI encoded
logger.debug(lsListQuery.getQueryUri());
\\This will give you the complete URL
logger.debug(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL());
\\ This should give the feed from which the columns can be read
ListFeed listFeed = service.getFeed(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL(), ListFeed.class);