Getting Google Images results via PHP?
August 11, 2008 5:07 AM   Subscribe

PHP maestros: how can I get Google Images results into my PHP code? See Guess the Google (Flash) for an example.

Is there a useful set of code that exists? I couldn't find it! I'm not averse to coding it from first principles but maybe you would be kind enough to nudge me in the right direction?
posted by basil1 to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
Best answer: Google's search API includes image search. It's called "AJAX API" but it's not really AJAX-specific. Because the API is straightforward, it's pretty simple to write the code yourself. You'd use something like file_get_contents to get the results and then json_decode to interpret the results. That should be all you need.
posted by scottreynen at 6:55 AM on August 11, 2008


Look at the google search api. Here is a code snippet for php access.
posted by hooray at 6:55 AM on August 11, 2008


Best answer: I've found Google's APIs to be lacking. (Flickr's API is far groovier. e.g. This JSON and jquery example is so elegant.)

The flash app you linked to actually just runs the query on Google (well actually, on a cache of the google page) which returns a big hunk of javascript and HTML.

The flash app just searches for the string "dyn.Img" and then extracts the components of the javascript. e.g. on the "tourist" question, this came up:

dyn.Img("http://www.snapmania.com/info/en/trm/wettbewerb.html&h=414&w=303&sz=80&hl=en&start=1","","L7ttv9RvX9LIuM:","http://www.snapmania.com/info/en/trm/pics/tourist.jpg","91","125","\x3cb\x3eTourist\x3c/b\x3e Remover","","","303 x 414 - 80k","jpg","www.snapmania.com","","","http://tbn0.google.com/images","1",[])

So, the link to google images is assembled with this info.

btw, Flash is easy to disassemble, so it's fun to look at flash files because most authors seem to think their code is secret. Poking around in the code, you can get a list of naughty words (profanity filter), the authors email address, a sendmail gateway to send spam, a proxy server which could be used for anonymous attacks on other servers, and info on how to submit your own VERY high score.

Oh and here are all the possible answers (see the keywords section).
posted by kamelhoecker at 7:07 AM on August 11, 2008 [1 favorite]


« Older Where art thou Os X print drivers for x7350?   |   As to why they did what they did to Mitiok... Newer »
This thread is closed to new comments.