Richard
Richard

Reputation: 1590

json google search curl proxy php

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:

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.

Upvotes: 0

Views: 1404

Answers (1)

Rudie
Rudie

Reputation: 53841

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

Upvotes: 1

Related Questions