Blogging Line

Blogging Tips and Resource

Parsing 4Shared SOAP API Using PHP

Parsing 4shared SOAP APIOn this occasion, I will share how to parse 4shared SOAP API Using PHP based on SIMPLEXML_LOAD_STRING. You can develop apps using 4shared API for mobile phones (iPhone, Android, Symbian, Blackberry, and Windows mobile), Windows, Mac, iPad, or Linux. With more than 50 API functions such as function upload / download, search for files, create and delete folders, etc., you can apply it according to the application you want and certainly 4shared API is available for free.

In this tutorial, I will create a sample application that is applied to the site using search function from 4shared SOAP API, specifically looking for mp3 files and mp3 download function.

The following code is the search function 4shared SOAP API by parsing the XML file into PHP.

<?php
$query = get_search_query();
$ext = 'mp3';
$perpage = 10;
if(get_query_var('paged') == 0)
$offset = 0;
else
$offset = get_query_var('paged') * $perpage - $perpage + 1;
$shared = 'http://search.4shared.com/network/searchXml.jsp?q='.urlencode($query).'&searchExtention='.$ext.'&searchmode=3&start='.$offset;
if(@fopen($shared,'r'))
{
$open = fopen($shared,'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);
if (!empty($xml->{'result-files'}->{'file'}))
{
echo '<ol>';
foreach(($xml->{'result-files'}->{'file'}) as $resultfiles)
{
echo '<li>';
echo '<span>'.$resultfiles->{'name'}.'</span><br/>'; // Display File Name
echo '<span>Downloaded for '.$resultfiles->{'downloads-count'}.' Times</span><br/>'; // Display Download Count
echo '<span>File Size: '.$resultfiles->{'size'}.'</span><br/>'; // Display File Size

echo '<a href='.$resultfiles->{'url'}.'>Download</a>'; // Display Link To Download File
echo '<span>'.$resultfiles->{'upload-date'}.'</span><div></div><br/>'; // Display Upload Date
echo '</li>' . "\n";
}
echo '</ol>' . "\n";
echo '<p>Result Total: '.$xml->{'total-files'}.'</p>' . " \n"; // Display Result Total
}
}
?>

Use this app wisely, do not let your site classified sites that infringe copyright. All questions and suggestions are appreciated.

4shared API 4shared SOAP API SIMPLEXML_LOAD_STRING 4shared apiphp 4shared download file4shared api php
Devan Nathaniel Avatar

About Devan Nathaniel P

Devan is a WordPress addict, had been living together since 2007 until now. He love Blogging and coding. this time He have dozens of websites, many of them are WordPress. besides active as a blogger, He also a WordPress themes developer