2012-02-28 41 views
2

我试图将查询传递给电子表格。我有一个价值说“约翰cena”。我如何在下面的行中传递它。而这样做在Google电子表格中查询列表时不接受ListQuery的空格

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) 

回答

3

对不起,我不完全知道答案,但我想帮助。

你可以尝试这样的事:

query.setSpreadsheetQuery("name = \"John cena\" and age > 25"); 

维基交@http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#SendingStructuredRowQueries说,你必须包括在报价空间数据。

+1

我试过了。它力求工作。我尝试过不同的可能性,比如单引号给它,提供下划线等。我有与列名相似的问题。但是,如果我在所有没有空格的小写字母中提供它,它确实有效。说全名。我已经把它作为全名。它适用于列名。 – user1238849 2012-02-29 23:15:30

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);