Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: WebAPI Allegro (połączenie)
Forum PHP.pl > Forum > PHP
The Night Shadow
  1. $params = array(
  2. 'sysvar' => 1,
  3. 'country-id' => 1,
  4. 'webapi-key' => 'KLUCZ'
  5. );
  6.  
  7. $soap = new SoapClient('http://webapi.allegro.pl/uploader.php?wsdl',array('encoding'=>'UTF8'));
  8. $result = $soap->__call('doQuerySysStatus',$params);
  9.  
  10. print_r($result);


Z jakiego powodu non stop wywala błąd :

Fatal error: Uncaught SoapFault exception: [ERR_INPUT_COUNTRY_ERROR] Invalid country code has been entered. in C:\Program Files\WebServ\httpd\allegro.php:10 Stack trace: #0 C:\Program Files\WebServ\httpd\allegro.php(10): SoapClient->__call('doQuerySysStatu...', Array) #1 {main} thrown in C:\Program Files\WebServ\httpd\allegro.php on line 10

Klucz api podaję ok. Całość zaciągnięta z dokumentacji AlLEGRO gdyby się kto pytał.
batman
A nie powinno być country-code zamiast country-id?
The Night Shadow
http://webapi.allegro.pl/uploader.php?apiM...sStatus#samples

Nie, ale sprawdziłem i nadal: nie. :- )

To wygląda trochę tak jakby do WebAPI nie dociearły zmienne z tablicy. Może trzeba jakoś SOAP skonfigurować?
batman
Rzeczywiście. W metodzie doQuerySysStatus jest country-id. country-code jest w doLogin.

Kiedyś temu napisałem takiego potworka do łączenia się z Allegro. Klasa korzysta z wbudowanego w PHP rozszerzenia SOAP. Może pomoże.
Nie konfigurowałem w żaden sposób SOAP, użyłem ustawień domyślnych.

  1. <?php
  2. class Allegro
  3. {
  4. const WEBAPI_URL = 'http://webapi.allegro.pl/uploader.php?wsdl';
  5. private $_data = array();
  6.  
  7. /**
  8. * @var SoapClient
  9. */
  10. private $_soap;
  11.  
  12. public function __construct($encoding = null, $userLogin = null, $userPassword = null, $webAPIKey = null, $localVersion = null) {
  13. if(!is_null($encoding)) $this->_data['encoding'] = $encoding;
  14. if(!is_null($userLogin)) $this->_data['userLogin'] = $userLogin;
  15. if(!is_null($userPassword)) $this->_data['userPassword'] = $userPassword;
  16. if(!is_null($webAPIKey)) $this->_data['webAPIKey'] = $webAPIKey;
  17. if(!is_null($localVersion)) $this->_data['localVersion'] = $localVersion;
  18.  
  19. $this->_soap = new SoapClient(self::WEBAPI_URL);
  20.  
  21. // sprawdzanie poprawnosci klucza wersji
  22. $sysStatus = $this->getAllegroSysStatus();
  23. if($this->_data['localVersion'] != $sysStatus['ver-key']) {
  24. $this->_data['localVersion'] = $sysStatus['ver-key'];
  25. }
  26. }
  27.  
  28. public function login() {
  29. $params = array (
  30. 'user-login' => $this->_data['userLogin'],
  31. 'user-password' => $this->_data['userPassword'],
  32. 'country-code' => 1,
  33. 'webapi-key' => $this->_data['webAPIKey'],
  34. 'local-version' => $this->_data['localVersion']);
  35.  
  36. return $this->doLogin($params);
  37. }
  38.  
  39. public function getAllegroSysStatus() {
  40. $params = array(
  41. 'sysvar' => 1, //which feature you are asking for, 1 is for AllegroWebApi, other possible options above
  42. 'country-id' => 1, //country code, 1 is for Poland, all country codes are available in doLogin method documentation
  43. 'webapi-key' => $this->_data['webAPIKey']);
  44.  
  45. return $this->doQuerySysStatus($params);
  46. }
  47.  
  48. public function __call($name, array $args = array()) {
  49. if(is_array($args[0])) $args = $args[0];
  50. return $this->_soap->__soapCall($name, $args);
  51. }
  52.  
  53. public function __get($name) {
  54. return $this->_data[$name];
  55. }
  56. }
  57. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.