The sample below shows how to render a set of headlines matching a hard coded search term.
<?php
# Configure the daylife api server url
$daylife_server = "freeapi.daylife.com";
$protocol = "phprest";
$version = "4.10";
$publicapi_access_url = "http://" . $daylife_server . "/" . $protocol . "/publicapi/" . $version . "/";
$method='search_getRelatedArticles';
# Configure your api credentials
$accesskey = "YOURKEYHERE";
$sharedsecret = "YOURSHAREDSECRETHERE";
# specify your query
$query = 'Yankee Stadium';
$url_encoded_query = urlencode($query);
# Build your method signature
# For search_X methods, the Core Input is the query term itself
$signature = md5($accesskey . $sharedsecret . $query);
#Draw from news in last 3 days
$end_time = date(U);
$start_time = $end_time - (3 * 86400);
$composed_url = $publicapi_access_url . $method . '?accesskey=' . $accesskey . '&signature=' . $signature . '&query=' . $url_encoded_query;
# kick off the call
$result = file_get_contents($composed_url);
$relatedArticlesResponse = unserialize($result);
$relatedArticles = $relatedArticlesResponse['response']['payload']['article'];
?>
<html>
<head>
<title>
DayPI headline demonstration
</title>
</head>
<body>
<p>The Method Call:<br>
<? print '<a href=http://'. $composed_url . '>' . $composed_url . '</a>'?>
<h1>Recent headlines for <? print $query ?></h1>
<ul>
<?
foreach ($relatedArticles as $article) {
$source = $article['source'];
$articleListing = "<li><b><a href=" . $article['url'] . ">" ;
$articleListing .= $article['headline'] . '</a></b>';
$articleListing .= " " . $article['timestamp'] . ", ";
$articleListing .= " from the <i><a href=" .$source['url'] . ">" . $source['name'] . "</a></i> " ;
echo $articleListing;
}
?>
</body>
</html>