如何使用字符串值查询 Google Spreadsheets API?
我正在使用 Zend_Gdata_SpreadsheetsListQuery。在 PHP 中,我的查询是:
"confirmation=$confirmation"
问题是 $confirmation = 'AB-CD-EFG-012345';
显然连字符导致查询出现问题,抛出的异常是:
未捕获异常“Zend_Gdata_App_HttpException”,消息为“预期响应代码 200,得到 400” 解析错误:遇到无效令牌'
如何引用或转义该值以免导致解析错误?单引号会导致相同的错误。
编辑:当我用双引号进行测试时,出现用户错误。双引号有效。
I am using Zend_Gdata_SpreadsheetsListQuery. In PHP my query is:
"confirmation=$confirmation"
The problem is that $confirmation = 'AB-CD-EFG-012345';
Apparently the hyphens are causing problems with the query and the exception thrown is:
Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400
Parse error: Invalid token encountered'
How can I quote or escape the value to not cause parse errors? Single quotes cause the same error.
Edit: When I was testing with double quotes there was user error. Double quotes work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
事实证明,我有两个电子表格,一个用于开发,一个用于生产,而且我没有查询我认为的那个电子表格。这个解决方案有效:
As it turns out I had two spreadsheets, one for dev and one for production and I was not querying the one I thought I was.. This solution works:
值得注意的是,逃跑时必须小心。我尝试过这个并没有得到任何快乐。我沿着这些思路尝试了很多组合:
但没有成功。通过 HTTP Inspector 运行流量(并设置 Zend HTTP Client 通过代理运行是另一件值得关注的事情!)我可以看到从这项工作生成的 URL 看起来像这样:
This was result in Invalid Token (Status [400] 400) 错误。它不喜欢 %5C%22 (\") 转义序列,但它从哪里得到它?!
事实证明,Zends 代码深处嵌入了一个“parse_str”,它在查询字符串中添加斜杠因为出于某种原因(Ubuntu 默认的 php 配置?) magic_quotes_gpc 在 php.ini 文件中被设置为 On ,
关闭它允许生成的 URL 恢复为:
已经开始工作了。
顺便说一句,我 诉诸于通过 HTTP 检查器运行它,因为这样做:
地报告了它在每个引号之前发送了上面没有 %5C 的字符串!
错误 如果您在 Zend 框架的 Gdata 类中遇到结构化查询问题,并且仅添加引号并不能解决问题,请快速查看一下您是否已将 magic_quotes_gpc 设置为 On!
It's worth noting, that you have to be careful with escaping. I tried this and didn't get any joy. I tried many combinations along these lines:
but to no avail. Running the traffic through an HTTP Inspector (and setting up your Zend HTTP Client to run through a proxy is another thing worth looking at!) I could see that the generated URLs from this work looking like this:
This was resulting in Invalid Token (Status 400) errors. It didn't like the %5C%22 (\") escape sequence, but where was it getting it from?!
It turns out that there is a "parse_str" embedded deep in Zends code, which was adding slashes to the query string because for some reason (Ubuntu default php config?) magic_quotes_gpc was set to On in the php.ini file.
Turning this off allowed the generated URLs to revert to:
and everything started working.
Incidentally, I had to resort to running it through an HTTP Inspector, because doing:
incorrectly reported that it was sending the string above without the %5C before each quote! Just goes to show, it never pays to trust what your code tells you...
So, if you have issues with structured queries in Zend framework's Gdata classes and just adding quotes doesn't solve it for you, have a quick look to see if you've got magic_quotes_gpc set to On!
我曾尝试为此研究 Zend 库,但没有任何乐趣。
难道是像用撇号包裹值一样简单吗?
您的代码:
可能的测试代码:
只是一个随机建议......
I have tried to research the Zend library for this, but am having no joy.
Could it be something as simple as wrapping the value in apostrophes?
Your code:
Possible code for testing:
Just a random suggestion...
您可以使用
urlencode
。但是,我希望 Zend API 能够为您处理该问题,因此请检查您是否正确使用它。You can use
urlencode
. However, I would expect the Zend API to handle that for you, so check that you're using it correctly.我的解决方案:
获取与查询不完全匹配的行 - 通过似乎没有禁止字母/符号的列。并在 php 脚本中对行进行过滤。
my solution:
get rows which does not match the query exactly - by the column which doesnt seem to have forbidden letters/signs. and in php script do filtering of the rows.