perl google soap示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了perl google soap示例相关的知识,希望对你有一定的参考价值。

  1. #!/usr/bin/perl
  2.  
  3. use SOAP::Lite;
  4. use strict;
  5. use warnings;
  6.  
  7. @ARGV == 2 or die "Usage: google <query> <number of results 1-10> ";
  8.  
  9. my $key='OS7mOjxQFHIztxIYU9yb8y3ibYgY4w2o';
  10.  
  11. my($query, $maxResults) = @ARGV;
  12.  
  13. my @params = ($key, $query, 0, $maxResults, 0, '', 0, '', 'latin1', 'latin1');
  14.  
  15. my $result = SOAP::Lite->service("file:GoogleSearch.wsdl")->doGoogleSearch(@params);
  16.  
  17. print "Result: ";
  18.  
  19. print join " ", map( { qq{$_->{URL}} } @{$result->{resultElements}} );
  20.  
  21.  
  22. Here is the Google include file:
  23.  
  24. <?xml version="1.0"?>
  25.  
  26. <!-- WSDL description of the Google Web APIs.
  27. The Google Web APIs are in beta release. All interfaces are subject to
  28. change as we refine and extend our APIs. Please see the terms of use
  29. for more information. -->
  30.  
  31. <!-- Revision 2002-08-16 -->
  32.  
  33. <definitions name="GoogleSearch"
  34. targetNamespace="urn:GoogleSearch"
  35. xmlns:typens="urn:GoogleSearch"
  36. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  37. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  38. xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  39. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  40. xmlns="http://schemas.xmlsoap.org/wsdl/">
  41.  
  42. <!-- Types for search - result elements, directory categories -->
  43.  
  44. <types>
  45. <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
  46. targetNamespace="urn:GoogleSearch">
  47.  
  48. <xsd:complexType name="GoogleSearchResult">
  49. <xsd:all>
  50. <xsd:element name="documentFiltering" type="xsd:boolean"/>
  51. <xsd:element name="searchComments" type="xsd:string"/>
  52. <xsd:element name="estimatedTotalResultsCount" type="xsd:int"/>
  53. <xsd:element name="estimateIsExact" type="xsd:boolean"/>
  54. <xsd:element name="resultElements" type="typens:ResultElementArray"/>
  55. <xsd:element name="searchQuery" type="xsd:string"/>
  56. <xsd:element name="startIndex" type="xsd:int"/>
  57. <xsd:element name="endIndex" type="xsd:int"/>
  58. <xsd:element name="searchTips" type="xsd:string"/>
  59. <xsd:element name="directoryCategories" type="typens:DirectoryCategoryArray"/>
  60. <xsd:element name="searchTime" type="xsd:double"/>
  61. </xsd:all>
  62. </xsd:complexType>
  63.  
  64. <xsd:complexType name="ResultElement">
  65. <xsd:all>
  66. <xsd:element name="summary" type="xsd:string"/>
  67. <xsd:element name="URL" type="xsd:string"/>
  68. <xsd:element name="snippet" type="xsd:string"/>
  69. <xsd:element name="title" type="xsd:string"/>
  70. <xsd:element name="cachedSize" type="xsd:string"/>
  71. <xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
  72. <xsd:element name="hostName" type="xsd:string"/>
  73. <xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
  74. <xsd:element name="directoryTitle" type="xsd:string"/>
  75. </xsd:all>
  76. </xsd:complexType>
  77.  
  78. <xsd:complexType name="ResultElementArray">
  79. <xsd:complexContent>
  80. <xsd:restriction base="soapenc:Array">
  81. <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ResultElement[]"/>
  82. </xsd:restriction>
  83. </xsd:complexContent>
  84. </xsd:complexType>
  85.  
  86. <xsd:complexType name="DirectoryCategoryArray">
  87. <xsd:complexContent>
  88. <xsd:restriction base="soapenc:Array">
  89. <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:DirectoryCategory[]"/>
  90. </xsd:restriction>
  91. </xsd:complexContent>
  92. </xsd:complexType>
  93.  
  94. <xsd:complexType name="DirectoryCategory">
  95. <xsd:all>
  96. <xsd:element name="fullViewableName" type="xsd:string"/>
  97. <xsd:element name="specialEncoding" type="xsd:string"/>
  98. </xsd:all>
  99. </xsd:complexType>
  100.  
  101. </xsd:schema>
  102. </types>
  103.  
  104. <!-- Messages for Google Web APIs - cached page, search, spelling. -->
  105.  
  106. <message name="doGetCachedPage">
  107. <part name="key" type="xsd:string"/>
  108. <part name="url" type="xsd:string"/>
  109. </message>
  110.  
  111. <message name="doGetCachedPageResponse">
  112. <part name="return" type="xsd:base64Binary"/>
  113. </message>
  114.  
  115. <message name="doSpellingSuggestion">
  116. <part name="key" type="xsd:string"/>
  117. <part name="phrase" type="xsd:string"/>
  118. </message>
  119.  
  120. <message name="doSpellingSuggestionResponse">
  121. <part name="return" type="xsd:string"/>
  122. </message>
  123.  
  124. <!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->
  125.  
  126. <message name="doGoogleSearch">
  127. <part name="key" type="xsd:string"/>
  128. <part name="q" type="xsd:string"/>
  129. <part name="start" type="xsd:int"/>
  130. <part name="maxResults" type="xsd:int"/>
  131. <part name="filter" type="xsd:boolean"/>
  132. <part name="restrict" type="xsd:string"/>
  133. <part name="safeSearch" type="xsd:boolean"/>
  134. <part name="lr" type="xsd:string"/>
  135. <part name="ie" type="xsd:string"/>
  136. <part name="oe" type="xsd:string"/>
  137. </message>
  138.  
  139. <message name="doGoogleSearchResponse">
  140. <part name="return" type="typens:GoogleSearchResult"/>
  141. </message>
  142.  
  143. <!-- Port for Google Web APIs, "GoogleSearch" -->
  144.  
  145. <portType name="GoogleSearchPort">
  146.  
  147. <operation name="doGetCachedPage">
  148. <input message="typens:doGetCachedPage"/>
  149. <output message="typens:doGetCachedPageResponse"/>
  150. </operation>
  151.  
  152. <operation name="doSpellingSuggestion">
  153. <input message="typens:doSpellingSuggestion"/>
  154. <output message="typens:doSpellingSuggestionResponse"/>
  155. </operation>
  156.  
  157. <operation name="doGoogleSearch">
  158. <input message="typens:doGoogleSearch"/>
  159. <output message="typens:doGoogleSearchResponse"/>
  160. </operation>
  161.  
  162. </portType>
  163.  
  164.  
  165. <!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->
  166.  
  167. <binding name="GoogleSearchBinding" type="typens:GoogleSearchPort">
  168. <soap:binding style="rpc"
  169. transport="http://schemas.xmlsoap.org/soap/http"/>
  170.  
  171. <operation name="doGetCachedPage">
  172. <soap:operation soapAction="urn:GoogleSearchAction"/>
  173. <input>
  174. <soap:body use="encoded"
  175. namespace="urn:GoogleSearch"
  176. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  177. </input>
  178. <output>
  179. <soap:body use="encoded"
  180. namespace="urn:GoogleSearch"
  181. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  182. </output>
  183. </operation>
  184.  
  185. <operation name="doSpellingSuggestion">
  186. <soap:operation soapAction="urn:GoogleSearchAction"/>
  187. <input>
  188. <soap:body use="encoded"
  189. namespace="urn:GoogleSearch"
  190. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  191. </input>
  192. <output>
  193. <soap:body use="encoded"
  194. namespace="urn:GoogleSearch"
  195. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  196. </output>
  197. </operation>
  198.  
  199. <operation name="doGoogleSearch">
  200. <soap:operation soapAction="urn:GoogleSearchAction"/>
  201. <input>
  202. <soap:body use="encoded"
  203. namespace="urn:GoogleSearch"
  204. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  205. </input>
  206. <output>
  207. <soap:body use="encoded"
  208. namespace="urn:GoogleSearch"
  209. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  210. </output>
  211. </operation>
  212. </binding>
  213.  
  214. <!-- Endpoint for Google Web APIs -->
  215. <service name="GoogleSearchService">
  216. <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
  217. <soap:address location="http://api.google.com/search/beta2"/>
  218. </port>
  219. </service>
  220.  
  221. </definitions>

以上是关于perl google soap示例的主要内容,如果未能解决你的问题,请参考以下文章

Google抛弃了了SOAP API,浮想联翩

使用新 oAuth 1.0 的 Google Ads API、C#、SOAP 请求?

perl 中的 google API 服务帐户流程

Perl 中的 Google 身份验证器实现

使用 SOAP 和 Javascript(Google Adwords Sandbox API)发送 GET 请求

8-Perl 哈希