Google Search API???

Thread Solved

Join Date: Sep 2007
Posts: 1,479
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Google Search API???

 
0
  #1
Sep 15th, 2009
Hi and I have been looking around and found that google has a few search api's but haven't yet found one that returns the results as a javascript/ajax array. Is it possible to at least get the google api to send the results to my website as a variable/array in javascript/ajax/php because can't see any reference to this.
PS. This is in the php section because all results will eventually end up in php. Also I tried the file_get_contents() function and curl on the google homepage but google knows it's a bot.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 849
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Google Search API???

 
1
  #2
Sep 15th, 2009
According to the section "PHP Access" in http://code.google.com/apis/ajaxsear...on/#The_Basics it should be possible.

My guess is you already tried this. At work we use the paid version of google search, which just returns xml.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,479
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Google Search API???

 
0
  #3
Sep 15th, 2009
From all the pages I clicked I didn't find that section. But does anybody know how to return 10 results instead of 4 ?
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 849
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: Google Search API???

 
0
  #4
Sep 15th, 2009
http://code.google.com/apis/ajaxsear..._class_GSearch

See the "Searchers" section. Appears to be limited to 4 or 8.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,479
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Google Search API???

 
0
  #5
Sep 15th, 2009
Any idea on how to implement that into the php script on the first link? I can't see how it fit's in but am trying to work it out.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,479
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Google Search API???

 
0
  #6
Sep 15th, 2009
I have solved it and will post some code soon.

Edit:
Here is the code which solved my problem:
  1. $searchterm='Paris Hilton';
  2. $searchterm=urlencode($searchterm);
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.$searchterm.'&start=0');
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6. curl_setopt($ch, CURLOPT_REFERER, 'http://www.syntax.cwarn23.info/');
  7. $body = curl_exec($ch);
  8. curl_close($ch);
  9. $string = json_decode($body);
  10. $dstring='';
  11. foreach ($string->responseData->results AS $val) {
  12. $dstring.='<<---<<>-><';
  13. $dstring.=str_replace(array('<<---<<>-><','<b>','</b>','<em>','</em>','<i>','</i>'),'',$val->title);
  14. $dstring.='<<---<<>-><';
  15. $dstring.=str_replace('<<---<<>-><','',$val->url);
  16. }
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL, 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.$searchterm.'&start=4');
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20. curl_setopt($ch, CURLOPT_REFERER, 'http://www.syntax.cwarn23.info/');
  21. $bodyb = curl_exec($ch);
  22. curl_close($ch);
  23. $stringb = json_decode($bodyb);
  24. foreach ($stringb->responseData->results AS $valb) {
  25. $dstring.='<<---<<>-><';
  26. $dstring.=str_replace(array('<<---<<>-><','<b>','</b>','<em>','</em>','<i>','</i>'),'',$valb->title);
  27. $dstring.='<<---<<>-><';
  28. $dstring.=str_replace('<<---<<>-><','',$valb->url);
  29. }
  30. $dstring=substr($dstring,11);
  31. //echo '<br>'.$dstring;
  32. $array=explode ('<<---<<>-><',$dstring);
  33. echo '<xmp>';
  34. print_r($array);
  35. echo '</xmp>';
Last edited by cwarn23; Sep 15th, 2009 at 10:13 am. Reason: added code
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Reply

Tags
ajax, api, google, javascript, php, search

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC