json 谷歌搜索curl 代理php
我目前面临一个与谷歌搜索、curl 和 json 有关的问题。
首先,我想向您展示我已有的代码: http://pastebin.com/LZzDZvHC
让我解释一下有关它的一些内容:
- 我没有显示我的密钥从 google 收到的
- $data 是我从提交的表单中获取的帖子
- ip 是用户 ip
- $url 显然是来自 googleapps 的 ajax 请求 url,
所以如果我打印出 $url 并将其放入浏览器中,我会得到一个不错的 JSON 返回- 工作完美。我想你已经猜到问题是什么了。
在这些声明之后我开始卷曲。
我得到一些东西并想将 json 转换为数组。
所以这就是问题所在: 我没有收到 JSON 返回,而是收到错误。
说:
400。这是一个错误。 您的客户发出了格式错误或非法的请求。这就是我们所知道的。
上面有一个漂亮的谷歌徽标。
所以我尝试将用户代理放入我的curl请求中->效果不太好。
不要担心我的 json_decode() - 我确实安装了并测试它,它工作正常!所以那里没有问题。
当我收到此错误消息时,我显然从 var_dump(); 中得到了“NULL”;
如果我不将 [assoc] 设置为 true,我的浏览器甚至不会显示我的网站。 (http://www.php.net/manual/en/function.json-decode.php)
现在请看一下来自google的文档: http://code.google.com/apis/websearch/docs/ 向下滚动到 Php Access
我可以想象这不仅是搜索的问题,也是其他谷歌服务的问题,因为在我看来,这就像一个限制,因为我的curl请求来自服务器。
我希望有人知道如何克服这个问题,因为我想使用它。
I am currently facing a problem that is concerning the google search, curl and json.
First of all I would like to show you the code I already have:
http://pastebin.com/LZzDZvHC
Let me explain some stuff about it:
- I am not showing the key that I received from google
- $data is the Post I am getting from the submitted form
- ip is the user ip
- $url is obviously the ajax request url from googleapps
so if I print out the $url and put it into my browser I get a nice JSON back - works perfectly. I suppose you can already guess what the problem is.
After those declarations I am starting the curl.
I get something back and want to convert the json to an array.
SO here is the problem:
I dont get JSON back I get an error back.
Saying:
400. That’s an error.
Your client has issued a malformed or illegal request. That’s all we know.
With a nice google logo on top of it.
So I tried to put a user agent into my curl request -> does not work as well.
Dont worry about my json_decode() - I did install and test it and it is working fine! SO there is no problem there.
As I get this error message I obviously get a "NULL" from the var_dump();
IF I dont set [assoc] to true my browser is not even showing my website.
(http://www.php.net/manual/en/function.json-decode.php)
Now please have a look at the docu from google:
http://code.google.com/apis/websearch/docs/
scroll down to Php Access
I could imagine that this is not only a problem with the search but also with other google services as it seems to me like a restriction as my curl request comes from a server.
I hope somebody has an idea how to overcome that problem because I would like to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
print $url;
的输出是什么?看起来合适吗?您可能需要对参数值进行 urlencode...当我打开 https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=oele&key=boele&userip =12.34.6.78
What's the output of
print $url;
? Does that look right? You might need to urlencode the paramter values...I see a nice JSON response when I open https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=oele&key=boele&userip=12.34.6.78