Извеждане на резултат от API

GOTI

Registered
Здравейте,

Напоследък съм зациклил и мисленето ми е затормозено :D

Чудя се как да изведа резултатите от приложение.

Имам app_id: secret: и url

Дайте съвет моля :lol:
 
GOTI каза:
Никой ли не разбира от API... :(
Ти реално нищо не си обяснил?

Ако си клиент на някаква Уеб Услуга, тази услуга би трябвало да ти върне някакъв резултат в някакъв формaт(XML/JSON). Парсваш резултата и това е?
 
Значи стигнах до тук и зацикли...

PHP:
<?php

$secret= "blablabla";
$apiurl = "http://domein.com/api/collections?app_id=20&secret=blablabla".$secret."&limit=28&keywords=final%20fantasy";

$cachetime = @filemtime("cache.json");
$diff = time() - $cachetime;


if($diff <= 60*60) {
	$results = json_decode(file_get_contents("cache.json"));
	$products = objectToArray($results);

} else {
	$products = array();
	$results = json_decode(file_get_contents($apiurl));
	
	$i = 0;
	
	foreach($results->results as $product){
		$products[$i]["pid"]      = $product->listing_id;
		$products[$i]["title"]    = $product->title;
		$products[$i]["url"]      = $product->url;
		$products[$i]["price"]    = $product->price;
		$products[$i]["quantity"] = $product->quantity;
		$products[$i]["endtime"]  = $product->ending_tsz;
		
		$imgs = json_decode(file_get_contents("http://domein.com/api/collections?app_id=20".$product->listing_id."/images?api_key=".$secret));
		
		$products[$i]["thumb"] = $imgs->results[0]->url_800x600;
		$products[$i]["image"] = $imgs->results[0]->url_570xN;
		
		$i++;
	}
	
	$jsonified = json_encode($products);
	
	$jsoncache = "cache.json";
	$fp = fopen($jsoncache, "w");
	fwrite($fp, $jsonified);
	fclose($fp);
	
	
} 


function objectToArray($d) {
	if (is_object($d)) {
		$d = get_object_vars($d);
	}

	if (is_array($d)) {

		return array_map(__FUNCTION__, $d);
	}
	else {

		return $d;
	}
}
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Demo Api</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

</head>

<body>
	<div id="w">
		<h1>Demo API</h1>
		
		<div id="products" class="clearfix">
		<?php
		
		foreach($products as $product) {
			echo "<div class=\"product\">\n";
			echo "<h2><a href=\"".$product['url']."\" target=\"_blank\">".$product['title']."</a></h2>\n";
			echo "<center><a href=\"".$product['url']."\" target=\"_blank\"><img src=\"".$product['thumb']."\" alt=\"".$product['title']." featured image\" class=\"thumb\"></a></center>\n";
			echo "<p>Price: <span class=\"price\">$".$product['price']."</span></p>\n";
			echo "<p>Quantity: ".$product['quantity']."</p>\n";
			echo "</div>\n";
		}
		?>
		
		</div>
	</div>
</body>
</html>

И не излизат резултатите и не излизат ...
Кажете къде бъркам :idea:
 

Back
Горе