SOAP not fetches result in PHP for Mouzenidis travel - php

I try to get results from http://api.mouzenidis-travel.com/search/ServiceMainSearch.svc?Wsdl
There is some methods to fetch data:
GetCountries // fetch available country data
GetCityDeparture(int countryID) //fetch available departure city data
GetFilter(int countryId, List departureCityId) // fetch others filters
// My PHP code:
$client = new SoapClient("http://api.mouzenidis-travel.com/search/ServiceMainSearch.svc?Wsdl");
$countryList = $client->GetCountries(); // results below
[0] => stdClass Object
(
[Code] => GR
[ID] => 29
[Name] => ГрециÑ
[NameLat] => Greece
)
[1] => stdClass Object
(
[Code] => CZ
[ID] => 6240
[Name] => ЧехиÑ
[NameLat] => Czech Republic
)
$cityDepObj = $client->GetCityDeparture(array('countryID'=>29));
[0] => stdClass Object
(
[Code] => MOW
[GroupName] => РоÑÑиÑ
[GroupNameLat] => РоÑÑиÑ
[GroupOrder] => 4
[ID] => 1
[Name] => МоÑква
[NameLat] => Moscow
[CountryID] => 460
[IsDeparture] => 1
[RegionID] => 0
)
[1] => stdClass Object
(
[Code] =>
[GroupName] => РоÑÑиÑ
[GroupNameLat] => РоÑÑиÑ
[GroupOrder] => 4
[ID] => 299
[Name] => ÐрхангельÑк
[NameLat] => Arkhangelsk
[CountryID] => 460
[IsDeparture] => 1
[RegionID] => 0
)
.
.
.
$client->GetFilter(array(29,array(1)));
Fatal error: Uncaught SoapFault exception: [s:Client] No connections available ...
I wrote to the Mouzendinis Tech Support, no results.
What make I wrong?

In C# this method requires field 'Country' as int, not an array of int. Also, other fields must be initialized as empty array or null.
The last field is a dictionary that caused filter update. For example: if you changed the city of departure, you should set the field to DictionaryEnum.CityDeparture

Can you check their API documentation and check what parameters required to pass to GetFilter method.

as you made $client->GetCityDeparture(array('countryID'=>29));, did you try with $client->GetFilter(array('countryId'=>29,'departureCityId'=>array(1))); ?
otherwise, try a wsdl to php geneator that'll ease you the requests construction and handling the response

Related

How to get the values from the following array?

I got the following array as a result of an output from a web service? I printed the values in the array using the print_r() method as stated in the following description.
ARRAY OUTPUT:
Array
( [0] => stdClass Object
( [return] => stdClass Object
( [data] => stdClass Object
(
[status] => 50000
[adminUser] => 1
[atdUserid] => 58
[category] => [client] => [cur_designation] => TL
[currentEmpId] => E058
[digitPrefix] => 8,5,1,3,7,0
[email] => jaliya#codegen.net
[employeeId] => 58
[employee_status] => 1
[firstName] => Jaliya
[lastName] => Seneviratna
[last_login_date] => stdClass Object ( [date] => 6 [month] => 2 [year] => 2015 )
[letterPrefix] => D,C,U,T,Z,E
[loginName] => jaliya
[resourceStatus] =>
[taskPassword] => d6188c72995d80e1a8e00d34987e0f6b
[userId] => 118 )
[reason] => Success
[refetch] => 1
[status] => 1
) ) )
I got the above array by calling a webservice in php. I want to get the details out of this array. And the problem was that I couldn't get the stdClass objects casted into the right type. I tried the following code but it is not working. Can anyone help me to get the values inside the data[] out in php. I used the following code and it is not working and giving an exception.
CODE USED:
print_r(array_values($quote));
echo $quote[0]->data;
The exception was the following...
EXCEPTION RECIEVED:
Notice: Undefined property: stdClass::$data in C:\xampp\htdocs\WebServiceDemo-php\democlient.php on line 27
How to get values out from this array?
Please help me...
convert the object in to array using this function
get_object_vars(array);
USE Can Print each key value of data array like this:-
echo $quote[0]->data->status;
I will Print
50000

Working with results of api in json array

I am using json to process a 3rd party api based on post code results. So far I have got
$json = json_decode(file_get_contents($remote_url, false, $context))
which provides the following results from a print_r:
stdClass Object ( [result] => stdClass Object ( [copyrightNotice] => © 2013-2014 StreetCheck. All Rights Reserved. Contains Ordnance Survey, Royal Mail, National Statistics and Land Registry data © Crown copyright and database right 2014. [postcode] => SN5 5RF [point] => stdClass Object ( [latitude] => 51.564896985 [longitude] => -1.837017086 ) [street] => Percheron Close [street2] => [locality] => Shaw [locality2] => [postTown] => Swindon [fullLocation] => Percheron Close, Shaw, Swindon, SN5 5RF [country] => England [outputArea] => E00078711 [largeUser] => [active] => 1 [ward] => stdClass Object ( [code] => E05002164 [name] => Shaw and Nine Elms ) [constituency] => stdClass Object ( [code] => E14000947 [name] => South Swindon ) [region] => stdClass Object ( [code] => E15000009 [name] => South West ) [commentary] => Percheron Close in Shaw is in the South West region of England. The postcode is within the Shaw and Nine Elms ward/electoral division, which is in the constituency of South Swindon. [urbanClassification] => Urban ) [message] => OK [success] => 1 )
Where the code above is the result from json.
How do I set the value of postcode to $postcode...
I have tried:
$postcode = $json['result']['postcode'] or [0]['postcode']
and got Fatal error:
Cannot use object of type stdClass as array in.
Could someone put me on right path please.
These are standard objects not arrays.
$json->result->postcode
if you want to keep your code the same, convert to php array.
// vvvv
$json = json_decode(file_get_contents($remote_url, false, $context), true);
this should fix you up.
As in case of your API response results in object of type stdClass.
So the result is in the form of object but not in the form of Array.
Read result like this :
<?php
$json = json_decode(file_get_contents($remote_url, false, $context));
$json->result->postcode;
?>
For reference visit : http://www.academia.edu/4092169/Get_data_from_string_with_JSON_object_in_PHP

How to find out Yahoo email address using Yahoo API PHP

so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }

Get values from SimpleXMLElement object

I am writing that post because i'm trying to solve a problem which seems to be stupid but unfortunately i cannot make it. I have an XML file (link) which i'm parsing with simplexml_load_file($link) as below:
function getListPoints($countryCode,$nbrPoints)
{
$xml_containt_url = "http://openchargemap.org/api/?output=xml&countrycode=".$countryCode."&maxresults=".$nbrPoints;
$xml_output = simplexml_load_file($xml_containt_url);
return $xml_output;
}
So when I print the xml output:
$infos_point = getListPoints("US",2);
print($infos_point);
I get everything I want, it gives me :
SimpleXMLElement Object
(
[ChargePoint] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[ID] => 2381
[UUID] => BFE199D5-07D4-4310-86D7-8BCB9092541D
[DateLastConfirmed] => 31/08/2010 00:00:00
[OperatorID] => 1
[OperatorTitle] => (Unknown Operator)
[DataProviderID] => 2
[NumberOfPoints] =>
[DataQualityLevel] => 1
[PercentageSimilarity] =>
)
[GeneralComments] => 1 SP Inductive
[AddressInfo] => SimpleXMLElement Object
(
[LocationTitle] => Sacramento County Public Garage
[AddressLine1] => 725 7th St
[AddressLine2] => SimpleXMLElement Object
(
)
[Town] => Sacramento
[StateOrProvince] => CA
[Postcode] => 95814
[Country] => United States
[Latitude] => 38.5846
[Longitude] => -121.4961
[ContactTelephone1] => 916-874-6227
[AccessComments] => 24 hours daily; pay lot
[RelatedURL] => SimpleXMLElement Object
(
)
)
The problem appears when i want to get some values of the SimpleXMLElement object, for example, I want to get the Town value, so I proceed as it follows :
$Town = $infos_point->ChargePoint[0]->AdressInfo->Town;
print($Town);
And it gives me a blank page. I have tried everything I've read on the internet and still nothing.
Maybe somebody can tell me what's happening ? it would be great as i will be able to continue my project.
It's your spelling of adDress. Should be: $Town = $infos_point->ChargePoint[0]->AddressInfo->Town;

Access array elements from API

For the life of me I can not figure out how to access the values of this array. Every example the stdClass Object has some type of value. If I try for example $obj->0->0->city; I get an error.
Can someone show me a example how to access [city] => toronto or even [date_created] => 2011-05-03 14:33:58?
I also tried this with no luck.
$object = $buy[1];
$title = $object->title[0];
echo "$title";
Thanks
This is what the api gives me.
stdClass Object
(
[id] => 1
[name] => toronto
[date_modified] => 2011-03-08 13:07:10
[tax_rate_provincial] =>
)
<br/>
Array
(
[0] => stdClass Object
(
[0] => stdClass Object
(
[id] => 28131844
[full_date] => 20110506
[end_date] => 20110511
[city] => toronto
[saved] => 1651
[discount_percentage] => 52
[deal_option] => Array
(
[0] => stdClass Object
(
[id] => 2600
[title] =>
[date_modified] => 0000-00-00 00:00:00
[date_created] => 2011-05-03 14:33:58
[value] => 3150
[price] => 1499
[deal_id] => 28131844
[is_default] => 0
)
)
[options] =>
[option_quantity] =>
[option_remaining] =>
[purchase_limit] => 1
[gift_limit] => 0
There is a special evil syntax to bypass numeric object attributes:
print $obj->{'0'}->{'0'}->city;
Is the correct syntax, and equivalent to the path you already determined.
Your second example is an array however, so it's probably:
print $array[0]->{'0'}->city;
The alternative is always to just foreach over a specific level - that works for objects and arrays likewise.

Categories