Skip to content
WJunction - Webmaster Forum

How to use Filesonic API for link checking

Status
Not open for further replies.
Hi guys,
How to use filesonic api for link checking for HTML site or wordpress.

This is api link for filesonic
Code:
http://api.filesonic.com/link#FSApi_Link-getInfo

How to send the link(eg:http://filesonic.com/54785/myfile.zip) and get the file info(file is live or dead) near the file.......??

i don't know what to do with this above link :'(, i am new to this, but some body please post how to do or link to any tutorial for "How to use API"
 

12 comments

First you gotta get all the links on the page. You can use regex for that.
Then you have the links like http://www.filesonic.com/file/4053274144

There's this in the API:
so you can put the ids with comma or one by one with "ids[]="
See? You get all the info as XML which you can then turn into an array in PHP, and do whatever you want with it.
 
In the link you gave the id is 54785 so you use that number as shown below

http://api.filesonic.com/link?method=getInfo&ids=54785


You'll see it returns

Code:
"links":[{"id":54785,"status":"NOT_AVAILABLE"}]

which means it's not available or in other words dead.

To have code that extracts the links from a Wordpress post and then get's the id's from that sends them to FileSonic and gets a return is quiet a bit of coding. Not that hard but will take a while to get rid of the bugs.
 
filesonic will always ban you ip (i cant stand them for this lol), we make bypass to them so you can check unlimited links enjoy it here - http://www.wjunction.com/92-development-area/111719-intelligent-url-checker-|-support-94-filehosts.html
Your the guy who refused to use their API so what do you expect, of course they'll IP ban you. In this case where he has a Wordpress site where he won't have hundreds of thousands of links to check it will be fine. Also by using the API it's far more accurate and he could even develop it into a link checker that trashes dead links.
 
http://www.wjunction.com/member.php?u=31729Thanks deliteblogger, Mr Happy, devNULL for your explaination.

1) Extracting id from the link.
2) Sending id to filesonic in this format
"http://api.filesonic.com/link?method=getInfo&ids=4053274144"
3) retrieving the data, it's return as xml

Code:
<FSApi_Link>
−
<getInfo>
−
<response>
−
<links>
−
<link>
<id>2302602951</id>
<filename>denis_horvat-hey_puzzle-web-2011-ukhx.zip</filename>
<size>19198510</size>
<description/>
<is_password_protected>0</is_password_protected>
<is_premium_only>0</is_premium_only>
<updated_on>2011-10-03 17:26:01</updated_on>
<status>AVAILABLE</status>
<url>http://www.filesonic.com/file/2302602951</url>
</link>
</links>
</response>
<status>success</status>
</getInfo>
</FSApi_Link>

4) Now using simple XML to extract text from XML

Code:
http://www.w3schools.com/PHP/php_xml_simplexml.asp

5)Integrating in wordpress/Html site.

Now coming to point, how to extract id from whole filesonic link...? i am struck in 1st point itself :(


http://www.wjunction.com/member.php?u=31729http://www.wjunction.com/member.php?u=10485
 
PHP:
$subject = 'blah blah 123 string http://www.filesonic.com/file/4053274144 blah blah...';
preg_match('/filesonic\.com\/file\/([0-9]+)/i',$subject,$matches);
$id=$matches[1];
echo $id;
will output:
4053274144
(edited)
 
Last edited:
PHP:
$subject = 'http://www.filesonic.com/file/4053274144';
preg_match('/filesonic\.com\/file\/([0-9]+)/i',$subject,$matches);
$id=$matches[1];
echo $id;
above code returns the id correctly(thanks deliteblogger).
Then i added the below code to fetch xml from filesonic api(http://api.filesonic.com/link?method=getInfo&ids=$id).
but it doesn't show anything.

PHP:
$url = 'http://api.filesonic.com/link?method=getInfo&ids=$id';
$str = file_get_contents($url);

function get_url_contents($url){
        $crl = curl_init();
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt($crl, CURLOPT_HEADER, 0);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
}

I dont need all the content from api's xml page, need only the Status wheather the file is alive or dead.

I want Result like below:

Code:
http://www.filesonic.com/file/4053274144  Available
http://www.filesonic.com/file/4436274165  Not Available
 
It doesn't get any simpler than this:
PHP:
<?php

$link = $_GET['url']; //change this to POST based if you want to.
$id = explode("/", $link);
$id = trim($id[4]);

$url = "http://api.filesonic.com/link?method=getInfo&ids=$id&format=json";

$page = file_get_contents($url);
$page = json_decode($page, TRUE);
$status = trim($page['FSApi_Link']['getInfo']['response']['links']['0']['status']);
echo $link . " --- " . $status;

?>


Output Screen:
Snap_2011.12.02_00h30m24s_002.png


EDIT: Right click and view the above image in a new window to see the full size.
 
Finally got it guys.

Thanks to deliteblogger, Lifetalk, Mr Happy, devNULL.

Note:
Hats off to deliteblogger and Lifetalk for your dedication.


Final Output:
b86c809287.png


this works only if we added the file url in php code......

How to automate this in wordpress......
 
Last edited:
a better looking code :)
<?php
if (isset(
$_GET['url'])){
$link = $_GET['url']; //change this to POST based if you want to.
$id = explode("/", $link);
$id = trim($id[4]);

$url = "http://api.filesonic.com/link?method=getInfo&ids=$id&format=json";

$page = file_get_contents($url);
$page = json_decode($page, TRUE);
$status = trim($page['FSApi_Link']['getInfo']['response']['links']['0']['status']);
echo
$link . " --- " . $status;
}
?>
​
 
Finally got it guys.

Thanks to deliteblogger, Lifetalk, Mr Happy, devNULL.

Note:
Hats off to deliteblogger and Lifetalk for your dedication.


Final Output:
b86c809287.png


this works only if we added the file url in php code......

How to automate this in wordpress......

Automating this in Wordpress requires quite a bit of coding. You'd have to parse the links in the posts, check them, then edit them to reflect the status. As Happy said, it can be done, but it'll take a while and the testing is frustrating. In that regard, unfortunately, you're on your own.
 
Status
Not open for further replies.

About the author

T
Senior Member · Joined
Helping Others
1,559
Messages
309
Reactions
83
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom