I am trying to fetch videos from youtube using below code:
$youtube_api_url = "https://www.googleapis.com/youtube/v3/search?key=".$new_key->api_key;
$youtube_api_url = $youtube_api_url."&order=relevance&type=video&maxResults=20&part=snippet&videoCategoryId=10&q=". urlencode(preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '',$trackRecord->name));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$youtube_api_url);
$result=curl_exec($ch);
$response = json_decode($result, true);
echo "<pre>"; print_r($response); die;
It is returning wrong number of results as below:
Array
(
[items] => Array
(
[0] => Array
(
[kind] => youtube#searchResult
[etag] => "m2yskBQFythfE4irbTIeOgYYfBU/ne5AZXpdoLtAn-mlwu4ipioOQ_I"
[id] => Array
(
[kind] => youtube#video
[videoId] => dB0ITzfbwfw
)
[snippet] => Array
(
[publishedAt] => 2017-01-23T17:31:23.000Z
[channelId] => UCdW5nPo1oyD2vLkvoYijmEg
[title] => Lihtz Kamraz "The Switch Up" Interview Part 2
[description] => In 2016, a lot of break out artists emerged and made a mark in the game. As 2017 begins, one name that you should definitely be on the lookout for is Lihtz ...
[thumbnails] => Array
(
[default] => Array
(
[url] => https://i.ytimg.com/vi/dB0ITzfbwfw/default.jpg
[width] => 120
[height] => 90
)
[medium] => Array
(
[url] => https://i.ytimg.com/vi/dB0ITzfbwfw/mqdefault.jpg
[width] => 320
[height] => 180
)
[high] => Array
(
[url] => https://i.ytimg.com/vi/dB0ITzfbwfw/hqdefault.jpg
[width] => 480
[height] => 360
)
)
[channelTitle] => HIPHOPSINCE1987TV
[liveBroadcastContent] => none
)
)
)
)
As you can see it is showing total and per page result as:
[pageInfo] => Array
(
[totalResults] => 14
[resultsPerPage] => 20
)
How can I get all results?
Related
So i was trying to get "title" and "Artist->name" from all the indexes
and i tried many times even used foreach but i am still learning curl and can only get it for the first index or a specific index here is the table
(
[data] => Array
(
[0] => Array
(
[id] => 2298089
[readable] => 1
[title] => Broken Strings
[title_short] => Broken Strings
[title_version] =>
[link] => https://www.deezer.com/track/2298089
[duration] => 250
[rank] => 749501
[explicit_lyrics] =>
[explicit_content_lyrics] => 0
[explicit_content_cover] => 0
[preview] => https://cdns-preview-1.dzcdn.net/stream/c-140e953bb38254bc8db4fe4dc97dd689-8.mp3
[md5_image] => 71698262cce4bb1c0e3d25e0707ed092
[artist] => Array
(
[id] => 4523
[name] => James Morrison
[link] => https://www.deezer.com/artist/4523
[picture] => https://api.deezer.com/artist/4523/image
[picture_small] => https://e-cdns-images.dzcdn.net/images/artist/794afe1359f598a28dc12c5496fefc2e/56x56-000000-80-0-0.jpg
[picture_medium] => https://e-cdns-images.dzcdn.net/images/artist/794afe1359f598a28dc12c5496fefc2e/250x250-000000-80-0-0.jpg
[picture_big] => https://e-cdns-images.dzcdn.net/images/artist/794afe1359f598a28dc12c5496fefc2e/500x500-000000-80-0-0.jpg
[picture_xl] => https://e-cdns-images.dzcdn.net/images/artist/794afe1359f598a28dc12c5496fefc2e/1000x1000-000000-80-0-0.jpg
[tracklist] => https://api.deezer.com/artist/4523/top?limit=50
[type] => artist
)
[album] => Array
(
[id] => 229099
[title] => Songs For You, Truths For Me (International Exclusive Bundle)
[cover] => https://api.deezer.com/album/229099/image
[cover_small] => https://e-cdns-images.dzcdn.net/images/cover/71698262cce4bb1c0e3d25e0707ed092/56x56-000000-80-0-0.jpg
[cover_medium] => https://e-cdns-images.dzcdn.net/images/cover/71698262cce4bb1c0e3d25e0707ed092/250x250-000000-80-0-0.jpg
[cover_big] => https://e-cdns-images.dzcdn.net/images/cover/71698262cce4bb1c0e3d25e0707ed092/500x500-000000-80-0-0.jpg
[cover_xl] => https://e-cdns-images.dzcdn.net/images/cover/71698262cce4bb1c0e3d25e0707ed092/1000x1000-000000-80-0-0.jpg
[md5_image] => 71698262cce4bb1c0e3d25e0707ed092
[tracklist] => https://api.deezer.com/album/229099/tracks
[type] => album
)
[type] => track
)
[1] => Array
(
[id] => 1196110412
etc.., and here is the code
$ch = curl_init();
$url = "https://api.deezer.com/search?q=broken%20strings";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
if($e = curl_error($ch)){
echo $e;
}else{
$decoded = json_decode($resp,true);
print_r($decoded);
}
curl_close($ch);
this posts all of array
$decoded['data'] will contain an array with all your records, so you want to foreach over that:
foreach ($decoded['data'] as $record) {
On each iteration of that loop, $record will be the subarray for each individual record. So on the first iteration, $record will be:
Array(
[id] => 2298089
[readable] => 1
[title] => Broken Strings
[title_short] => Broken Strings
[title_version] =>
[link] => https://www.deezer.com/track/2298089
[duration] => 250
[rank] => 749501
...
Then you can reference each field in that array like $record['id'] or $record['link']. To "drill down" into multi-dimensional arrays, just stack consecutive [] references, like $record['album']['id'] or $record['artist']['link'].
All together:
foreach ($decoded['data'] as $record) {
printf("Title: %s\n", $record['title']);
printf("Artist: %s\n\n", $record['artist']['name']);
}
I am using php curl to get account and transaction data from the plaid api. I'd like to see it in a nice format so I can go about creating loops to save the information into a database. The decoded json output, when printed with print_r, is returned like this:
array ( [accounts] => Array ( [0] => Array ( [_id] => QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA [_user] => eJXpMzpR65FP4RYno6rzuA7OZjd9n3Hna0RYa [balance] => Array ( [available] => 1203.42 [current] => 1274.93 ) [institution_type] => fake_institution [meta] => Array ( [name] => Plaid Savings [number] => 9606 ) [subtype] => savings [type] => depository ) [1] => Array ( [_id] => nban4wnPKEtnmEpaKzbYFYQvA7D7pnCaeDBMy [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA...
I'd like to get it looking like this:
Array (
[accounts] => Array (
[0] => Array (
[_id] => QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK
[_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA
[_user] => eJXpMzpR65FP4RYno6rzuA7OZjd9n3Hna0RYa
[balance] => Array (
[available] => 1203.42
[current] => 1274.93 )
[institution_type] => fake_institution
[meta] => Array (
[name] => Plaid Savings
[number] => 9606 )
[subtype] => savings
[type] => depository )
[1] => Array (
[_id] => nban4wnPKEtnmEpaKzbYFYQvA7D7pnCaeDBMy
[_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA
`
For reference, here is the code to get the response:
$data = array(
"client_id"=>"test_id",
"secret"=>"test_secret",
"access_token"=>"test_chase"
);
$string = http_build_query($data);
//initialize session
$ch=curl_init("https://tartan.plaid.com/connect/get");
//set options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute session
$accountData = json_decode(curl_exec($ch), true);
print_r($accountData);
//close session
curl_close($ch);
Any thoughts other than loops?
I am working with project on TECDOC. get known about TECDOC http://webservicepilot.tecdoc.net/pegasus-2-0/ here.
So on this page http://webservicepilot.tecdoc.net/pegasus-2-0/test2/index.html
in the dropdown menu you will find functions getVehicleByIds(), getVehicleByIds2(), getVehicleByIds2StringList() and getVehicleByIdsStringList().
In above functions You will find a carIds field which have datatype as longList (for first two function) or StringList (for other two functions).
Now I while calling this function from PHP I have to pass arguments of this field in lonlList or StringList datatype which is not available in PHP and yes know generally for this task generally php array is used. But it is not working here.
here is code...
<?php
$url ="http://webservicepilot.tecdoc.net/pegasus-2-0/wsdl/TecdocToCat";
$trace = array('trace' => 1);
$client = new SoapClient($url, $trace);
$request_array = array(
'country'=>'pt',
'countryUserSetting'=>'CH',
'lang'=>'pt',
'motorCodes'=>true,
'provider'=>'452',
'vehicleTerms'=>true,
'carIds'=>1116,
'passengerCarDetails'=>true
);
echo "<pre>";
$responce = $client->getVehicleByIds($request_array);
print_r($responce);
?>
note : there are some documents provided in first link I post.
please refer InterfaceCatService.pdf for each function datatype details study.
please help me.
I can see the output like below.
stdClass Object
(
[data] => stdClass Object
(
[array] => Array
(
)
[empty] => 1
)
[status] => 200
[statusText] =>
)
Hello Again,
I have tried with CURL...by using soapclient there is issue with longlist carIds. so we can do with CURL request.
got the below output.
Array
(
[data] => Array
(
[array] => Array
(
[array] => Array
(
[0] => Array
(
[carId] => 1116
[motorCodes] => Array
(
[array] => Array
(
[array] => Array
(
[motorCode] => DZ
)
)
[empty] => false
)
[passengerCarDetails] => Array
(
[brakeSystem] => Hidráulico
[constructionType] => três volumes
[cylinder] => 4
[cylinderCapacityCcm] => 1781
[cylinderCapacityLiter] => 180
[fuelType] => Gasolina
[fuelTypeProcess] => Injecção no colector de admissão/carburador
[impulsionType] => Tracção dianteira
[manuName] => AUDI
[modelName] => 80 (89, 89Q, 8A, B3)
[motorType] => Otto
[powerHP] => 112
[powerKW] => 82
[typeName] => 1.8 E
[typeNumber] => 1116
[valves] => 2
[yearOfConstructionFrom] => 198606
[yearOfConstructionTo] => 199108
)
[vehicleDetails] => Array
(
[axisConfiguration] => Array
(
[#value] =>
[#attributes] => Array
(
[nil] => true
)
)
[carId] => 1116
[ccmTech] => 1781
[constructionType] => três volumes
[manuId] => 5
[modId] => 31
[powerHpFrom] => 112
[powerHpTo] => 112
[powerKwFrom] => 82
[powerKwTo] => 82
[tonnage] => Array
(
[#value] =>
[#attributes] => Array
(
[nil] => true
)
)
[yearOfConstrFrom] => 198606
[yearOfConstrTo] => 199108
)
[vehicleTerms] => Array
(
[carId] => 1116
[carType] => 1.8 E
[manuId] => 5
[manuName] => AUDI
[modId] => 31
[modelName] => 80 (89, 89Q, 8A, B3)
)
)
[1] => Array
(
[carId] => 1117
[motorCodes] => Array
(
[array] => Array
(
[array] => Array
(
[motorCode] => SD
)
)
[empty] => false
)
[passengerCarDetails] => Array
(
[brakeSystem] => Hidráulico
[constructionType] => três volumes
[cylinder] => 4
[cylinderCapacityCcm] => 1847
[cylinderCapacityLiter] => 180
[fuelType] => Gasolina
[fuelTypeProcess] => Injecção no colector de admissão/carburador
[impulsionType] => Tracção dianteira
[manuName] => AUDI
[modelName] => 80 (89, 89Q, 8A, B3)
[motorType] => Otto
[powerHP] => 113
[powerKW] => 83
[typeName] => 1.8
[typeNumber] => 1117
[valves] => 2
[yearOfConstructionFrom] => 198609
[yearOfConstructionTo] => 198807
)
[vehicleDetails] => Array
(
[axisConfiguration] => Array
(
[#value] =>
[#attributes] => Array
(
[nil] => true
)
)
[carId] => 1117
[ccmTech] => 1847
[constructionType] => três volumes
[manuId] => 5
[modId] => 31
[powerHpFrom] => 113
[powerHpTo] => 113
[powerKwFrom] => 83
[powerKwTo] => 83
[tonnage] => Array
(
[#value] =>
[#attributes] => Array
(
[nil] => true
)
)
[yearOfConstrFrom] => 198609
[yearOfConstrTo] => 198807
)
[vehicleTerms] => Array
(
[carId] => 1117
[carType] => 1.8
[manuId] => 5
[manuName] => AUDI
[modId] => 31
[modelName] => 80 (89, 89Q, 8A, B3)
)
)
)
)
[empty] => false
)
)
Below is the code to get response using CURL.
$soap_request = "<?xml version=\"1.0\"?>\n";
$soap_request .= '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://path- to/schemas" xmlns:urn="urn:axis.server.cat.tecdoc.net" xmlns:car="http://carselection.datatype.tocinterface.cat.tecdoc.net" xmlns:dat="http://datatype.cat.tecdoc.net" xmlns:tec="http://webservicepilot.tecdoc.net/pegasus-2-0/services/TecdocToCatWL">
<soapenv:Header/>
<soapenv:Body>
<urn:getVehicleByIds>
<urn:in0>
<car:carIds>
<dat:array>
<tec:item>1116</tec:item>
<tec:item>1117</tec:item>
</dat:array>
</car:carIds>
<car:country>pt</car:country>
<car:countryUserSetting>CH</car:countryUserSetting>
<car:lang>pt</car:lang>
<car:motorCodes>true</car:motorCodes>
<car:passengerCarDetails>true</car:passengerCarDetails>
<car:provider>292</car:provider>
<car:vehicleTerms>true</car:vehicleTerms>
</urn:in0>
</urn:getVehicleByIds>
</soapenv:Body>
</soapenv:Envelope>';
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://webservicepilot.tecdoc.net/pegasus-2- 0/services/TecdocToCatWL?wsdl" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
curl_setopt($soap_do, CURLOPT_PROXY, IF_ANY);
$result = curl_exec($soap_do);
Thanks,
Gaurang
you need to convert the array to tecdoc list type.
Its very easy though, make a stdClass object with 2 fields.
empty and array
set empty to false and array to the array of carIds like
$carIds = array(1116);
$obj = new stdClass();
$obj->empty = false;
$obj->array = $carIds;
now pass $obj in the params list of soap request
$request_array = array(
'country'=>'pt',
'countryUserSetting'=>'CH',
'lang'=>'pt',
'motorCodes'=>true,
'provider'=>'292',
'vehicleTerms'=>true,
'carIds'=> $obj,
'passengerCarDetails'=>true
);
better make a function which converts the array to above object structure, the empty flag will be set to true if array is null or empty
I'm running a curl request and it returns the below:
Array
(
[#attributes] => Array
(
[exp_cid] => 0BqO
)
[REQUEST] => Array
(
[#attributes] => Array
(
[type] => RETURN
[subtype] => CALLBUR
[EXP_ExperianRef] =>
[success] => Y
[timestamp] => Mon, 10 Feb 2014 at 10:28 AM
[id] => 0BqO
)
[MB01] => Array
(
[#attributes] => Array
(
[seq] => 01
)
[DATEOFTRANSACTION] => 20100901
[VRM] => MYREG
[VINCONFIRMATIONFLAG] => 0
[ENGINECAPACITY] => 01360
[DOORPLAN] => 14
[DATEFIRSTREGISTERED] => 20041007
[YEAROFMANUFACTURE] => 2004
[SCRAPPED] => 0
[EXPORTED] => 0
[IMPORTED] => 0
[MAKE] => PEUGEOT
[MODEL] => 307 ENVY 90
[COLOUR] => BLACK
[TRANSMISSION] => MANUAL 5 GEARS
[ENGINENUMBER] => EE
[VINSERIALNUMBER] => VF
[DOORPLANLITERAL] => 5 DOOR HATCHBACK
[MVRISMAKECODE] => L1
[MVRISMODELCODE] => BJJ
[DTPMAKECODE] => L1
[DTPMODELCODE] => 892
[TRANSMISSIONCODE] => M
[GEARS] => 5
[FUEL] => PETROL
[CO2EMISSIONS] => 155
[USEDBEFORE1STREG] => 0
[IMPORTNONEU] => 0
[UKDATEFIRSTREGISTERED] => 20041007
[MAXPERMISSIBLEMASS] => 01639
[MAXNETPOWER] => 085
[MAXTRAILERWEIGHTBRAKED] => 01000
[MAXTRAILERWEIGHTUNBRAKED] => 00620
[SOUNDLVLSTATIONARY] => 079
[SOUNDLEVELENGINESPEED] => 03938
[SOUNDLVLDRIVEBY] => 71
[SEATINGCAPACITY] => 005
[MASSINSERVICE] => 000001245
[MAKEMODEL] => PEUGEOT 307 ENVY 90
)
[MB37] => Array
(
[#attributes] => Array
(
[seq] => 01
)
[V5CDATACOUNT] => 02
[V5CDATAITEMS] => Array
(
[0] => Array
(
[DATE] => 20090825
)
[1] => Array
(
[DATE] => 20041007
)
)
)
)
)
I'm struggiling to access the return, I've tried the following but it doesn't return anything:
foreach ($xml->REQUEST->MB01 as $requestData) {
echo $requestData;
}
My other problem is depending on the vehicle reg it will return different MB blocks, is there away to return them if they are returned.
Thanks.
EDIT
This is the full code that I'm running, when it's ran all I get is < Does this mean anything?
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output[0]['REQUEST']['MB01']['DATEOFTRANSACTION'];
Cheers guys.
The return is an array, not an object. Try this :
foreach ($xml['REQUEST']['MB01'] as $requestData) {
if(is_array($requestData) {
print_r($requestData);
} else {
echo $requestData;
}
}
php code:
<?php
$url = 'https://www.rudolphs-christmasshop.com.au/api/v2/products/';
$username ='xyz'; $password ='ca25fe6947564b9479sdfsaffsaffasfasfsaffdasfe5866b4';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD,$username . ':' . $password);
$result = curl_exec($ch); curl_close($ch);
$xml = simplexml_load_string($result);
?>
output
SimpleXMLElement Object (
[product] => Array (
[0] => SimpleXMLElement Object (
[id] => 29
[name] => SimpleXMLElement Object ( )
[type] => physical
[sku] => 22254
[description] => SimpleXMLElement Object ( )
[search_keywords] => SimpleXMLElement Object ( )
[availability_description] => SimpleXMLElement Object ( )
[price] => 22.9500
[inventory_warning_level] => 5
[warranty] => SimpleXMLElement Object ( )
[weight] => 0.2500
[width] => 13.0000
[height] => 11.0000
[depth] => 8.0000
[view_count] => 125
[page_title] => Aussie Koala and Baby Christmas Ornament - Australiana
[meta_keywords] => koala bear decoration, koala christmas ornament, australian decorations, aussie christmas, christmas decoration
[meta_description] => SimpleXMLElement Object ( )
[layout_file] => product.html
[is_price_hidden] => false
[price_hidden_label] => SimpleXMLElement Object ( )
[categories] => SimpleXMLElement Object (
[value] => 30
)
[downloads] => SimpleXMLElement Object (
[link] => /products/29/downloads )
[images] => SimpleXMLElement Object (
[link] => /products/29/images
)
)
)
)
)
How could I get the image url and display image on browser
May be wrong but I guess like this if I look here
echo $xml->product[0]->downloads->images->link;
But if you show us your XML we are more able to help you.
Greets
I can't test it here. But you can access the tree with:
if you have more products:
<?php
foreach($xml->product as $pout ) {
echo $pout->downloads->images->link;
}
?>
if you want only one product something like this:
$xml->product[0]->downloads->images->link;