AAA Главная
Примеры PHP Примеры JavaScript Примеры Ajax Примеры CSS,HTML

Использование API Google


Для выполнения до 1000 XML запросов к Google в день Вам предварительно необходимо зарегистрироваться и получить ключ.


 search="Word"
 xmlhttp.open("POST", "http://api.google.com/search/beta2",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   alert(xmlhttp.responseText)
  }
 }
 xmlhttp.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1")
 xmlhttp.setRequestHeader("MessageType", "CALL")
 xmlhttp.setRequestHeader("Content-Type", "text/xml")

 xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+"<SOAP-ENV:Envelope"+
      ' xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
      ' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"'+
      ' xmlns:xsd="http://www.w3.org/1999/XMLSchema">'+
      '<SOAP-ENV:Body><ns1:doGoogleSearch'+
      ' xmlns:ns1="urn:GoogleSearch"'+
      ' SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
      '<key xsi:type="xsd:string">GOOGLEKEY</key> <q'+
      ' xsi:type="xsd:string">'+search+'</q> <start'+
      ' xsi:type="xsd:int">0</start> <maxResults'+
      ' xsi:type="xsd:int">10</maxResults> <filter'+
      ' xsi:type="xsd:boolean">true</filter> <restrict'+
      ' xsi:type="xsd:string"></restrict> <safeSearch'+
      ' xsi:type="xsd:boolean">false</safeSearch> <lr'+
      ' xsi:type="xsd:string"></lr> <ie'+
      ' xsi:type="xsd:string">latin1</ie> <oe'+
      ' xsi:type="xsd:string">latin1</oe>'+
      '</ns1:doGoogleSearch>'+
    '</SOAP-ENV:Body></SOAP-ENV:Envelope>')

Google is using a SOAP interface, many people think SOAP has some serious issues worth considering. REST is probably a better model as it works with the current web framework, proxies, caches etc. So whilst we can use the XML HTTP Request object to talk soap, it's probably best not to unless you have no control over what's happening on the server end.

By default the object can only call back to the same server, in a reduced security environment (accessed from file:// say) IE can access any domain, Mozilla can also do that if you request and are granted the appropriate permissions see "a google thread I can't get to offline!"


.

© Copyright 2008- by KDG



Rambler's Top100