Script author: jon
Receiving an article
     It is shown in this example how to receive data via API from other webpages or uCoz sites with the help of php-scripts. Script sends the request to the main page of the website by means of API and receives a list of articles. Then it selects the URL of the latest (the newest) article and sends the request to API once again. But this time it is a request for this very article. The results turn back in XMLRPC format. When the necessary article is received, the script displays its title, content, author and the link to the source on the current page. This script can be used for the cross-posting, receiving and processing data on the entries via API or for making rewrites (but after some improvement). The source code of this example is shown below.

In the template of the page:

<div
align="center">
    <p>
        <b>This example shows the way of using the script to receive the latest article from the uCoz Official Blog</b>
    </p>
</div>
<hr>
<?$PHPCODE$("http://phpexample.ucoz.com/php/example003/example003.php")?>


PHP-script of this example:

<?php
$context = stream_context_create(array('http' => array('method' => "GET", 'header' => "Content-Type: text/xml",)));
$file = file_get_contents("http://blog.ucoz.ru/api/blog/", false, $context);
$response = xmlrpc_decode($file,"utf8");
if ($response && xmlrpc_is_fault($response))
{
    echo "Can't receive data, try again later";
    exit;
}
$lastmat=preg_replace("/\/blog\//i","/api/blog/",$response[0]['ENTRY_URL']);
$file = file_get_contents($lastmat, false, $context);
$response = xmlrpc_decode($file,"utf8");
if ($response && xmlrpc_is_fault($response))
{
    echo "Can't receive data, try again later";
    exit;
}
echo "<center><h1>".$response['TITLE']."</h1></center><br>
<div>".$response['MESSAGE']."</div>
<p>Author: ".$response['USER_NAME']."</p>
<p>Source: <a href='".$response['ENTRY_URL']."'>".$response['ENTRY_URL']."</a></p>";
?>
Date 18.02.2011
Comments:
Electric Hà Spam 16.05.2014 13:07
I want to perform as this article.
But with a category, not an article.
Plz help me!
Only registered users can add comments.
[ Registration | Login ]