Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Mydlane PHP, PHP + cURL + SOAP => Google Api
tnkywe
post 2.08.2005, 19:40:18
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 2.08.2005

Ostrzeżenie: (0%)
-----


Witam,
Probowalem stworzyc skrypt wykorzystujacy cURL'a oraz SOAP do laczenia sie z serwisem Google (z wykorzystaniem ich API).
Oto co stworzylem (odrazu mowie ze nie znam sie ani SOAP, mistrzem w php tez nie jestem):

  1. <?php
  2. $url='http://api.google.com/search/beta2';
  3. $host='api.google.com';
  4. $akcja='urn:GoogleSearchAction';
  5.  
  6. $request = '<'.'?xml version=\"1.0\" encoding=\"ISO-8859-1\"?'.'>
  7. <SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:typens=\"urn:GoogleSearch\">
  8. <SOAP-ENV:Body>
  9. <typens:doGoogleSearch xmlns:typens=\"urn:GoogleSearch\">
  10. <key xsi:type=\"xsd:string\">XXXXXXXXXXXXXXXXXXXXXXXX</key>
  11. <q xsi:type=\"xsd:string\">asdasd</q>
  12. <start xsi:type=\"xsd:int\">0</start>
  13. <maxResults xsi:type=\"xsd:int\">10</maxResults>
  14. <filter xsi:type=\"xsd:boolean\">true</filter>
  15. <restrict xsi:type=\"xsd:string\"></restrict>
  16. <safeSearch xsi:type=\"xsd:boolean\">false</safeSearch>
  17. <lr xsi:type=\"xsd:string\"></lr>
  18. <ie xsi:type=\"xsd:string\">latin</ie>
  19. <oe xsi:type=\"xsd:string\">latin</oe>
  20. </typens:doGoogleSearch>
  21. </SOAP-ENV:Body>
  22. </SOAP-ENV:Envelope>';
  23.  
  24. $header[] = &#092;"Host: $host\";
  25. $header[] = &#092;"Accept: text/html;q=0.5, application/soap+xml\";
  26. $header[] = &#092;"Content-length: \".strlen($request);
  27. $header[] = &#092;"Connection: close\";
  28. $header[] = &#092;"SOAPAction: $akcjarn\";
  29. $header[] = $request;
  30.  
  31. $ch = curl_init();
  32. curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
  33. curl_setopt($ch, CURLOPT_URL, $url);
  34. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  35.  
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
  37. curl_setopt($ch, CURLOPT_HEADER, 1); 
  38. $data=curl_exec($ch);
  39. curl_close($ch);
  40.  
  41. print('<h1>Wynik:</h1><pre>'.$data.'</pre>');
  42.  
  43. ?>


jako output dostaje:
  1. <h1>Wynik:</h1><pre>HTTP/1.1 500 Internal Server Error
  2. Content-Type: text/xml; charset=utf-8
  3. Cache-control: private
  4. Transfer-Encoding: chunked
  5. Date: Tue, 02 Aug 2005 18:39:17 GMT
  6. Server: GFE/1.3
  7. Connection: Close
  8.  
  9. <?xml version='1.0' encoding='UTF-8'?>
  10. <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">
  11. <SOAP-ENV:Body>
  12. <SOAP-ENV:Fault>
  13. <faultcode>SOAP-ENV:Server.Exception:</faultcode>
  14. <faultstring>java.lang.NullPointerException</faultstring>
  15. <faultactor>/search/beta2</faultactor>
  16. </SOAP-ENV:Fault>
  17.  
  18. </SOAP-ENV:Body>
  19. </SOAP-ENV:Envelope>
  20. </pre>


Niezbyt rozumiem co zle zrobilem smile.gif

Ten post edytował tnkywe 2.08.2005, 19:42:35
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
NuLL
post 3.08.2005, 01:38:15
Post #2





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

Ostrzeżenie: (0%)
-----


Czy to temat na Pro - wątpie

Pro -> php


--------------------
Javascript, Coffeescript, Node.js, Mongo, CouchDb, chmury, workery & inne bajery - zycie jest zbyt krotkie aby miec nudna prace :)
Go to the top of the page
+Quote Post
tnkywe
post 3.08.2005, 10:51:24
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 2.08.2005

Ostrzeżenie: (0%)
-----


Ok. Sorry chyba zle odczytalem to "pro" smile.gif Zagadnienie jest dosyc zaawansowane, myslalem ze na "pro" wiecej osob bedzie zorientowanych.
Tak czy siak probowal ktos napisac wlasna obsluge SOAPa w php ?
Wczesniej korzystalem z nusoap jednak tez byly problemy(akurat z przesylaniem naglowkow SOAP) sad.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 08:58