The audience search feed collects the children of a given audience interest id.
Audience Interest Search
For more information, browse the Audience Interest Search API
Request:
Response:
<searchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="feedschema/base.xsd" totalResultCount="1" currentPage="1" currentPageResultCount="1" totalPageCount="1">
<audienceInterestResult id="530006" name="Events">
<children>
<audienceInterestResult id="141301" name="Arts"/>
<audienceInterestResult id="141307" name="Classical Music"/>
<audienceInterestResult id="141302" name="Festivals & Heritage"/>
<audienceInterestResult id="139861" name="Gay & Lesbian"/>
<audienceInterestResult id="140266" name="Kids & Family"/>
<audienceInterestResult id="141303" name="Lifestyle"/>
<audienceInterestResult id="141304" name="Music & Nightlife"/>
<audienceInterestResult id="141306" name="Science & Knowledge"/>
<audienceInterestResult id="141305" name="Sport & Outdoors"/>
<audienceInterestResult id="140265" name="Weird & Wonderful"/>
</children>
</audienceInterestResult>
</searchResponse> Call the feed URL, using curl
$ch = curl_init(); // Set up curl
curl_setopt($ch, CURLOPT_URL, $url); // Add url
curl_setopt($ch, CURLOPT_HEADER, 0); // Remove header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Set timeout, 10s
$response = curl_exec($ch); // Call feed
curl_close($ch); // Close curl, free resources
Convert response to XML, use xpath to get the Audience interests tree
$audienceInterestResponse = new SimpleXMLElement($response); // Create xml object
$audienceInterestResults = $audienceInterestResponse->audienceInterestResult; //Use xpath to get list of audience interests
Build output dynamically by iterating the list
<div>
<ul>
<?php foreach ($audienceInterestResults as $audienceInterest ) { ?>
<li><a href="#"><?php echo $audienceInterest["name"];?> </a>
<?php if ($audienceInterest->children) {?>
<ul>
<?php foreach ($audienceInterest->children->audienceInterestResult as $audienceInterestChild ) { ?>
<li><a href="#"><?php echo $audienceInterestChild["name"];?></a></li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
Loading...
