filesonic.com API tutorial

Status
Not open for further replies.

hihotfile

Active Member
145
2010
35
0
why i am creating this topic ?
Because i can't find this nowhere ...please note that i am not Big php programmer ... just a newbie in this field :facepalm: But believe master of Php one day =) (Because my wife says to me "Always think good because it willl be happen in future")

i starting php for fun...but i think it is now necessary me for automation tool beacuse i am just too lazy to click.

caution : X-( it is beginning

For Masters of Php : <3 Please share your knowledge and valuable comments about this .Thanks :D

so come to point :)
-------------------------------------------------------------------------

file sonic API page :

http://api.filesonic.com/l


FSApi_User

This API call allow you to get/set information related to the user. getInfo (login required)

Get the current user informations such as:
- id
- email
- nickname
- is_premium (1 if premium, 0 if not premium)
- premium_expiration (not returned if is_premium is not 1)

@see FSApi_Auth::login

@return Array

@example http://api.filesonic.com/user?method=getInfo&u=USER-EMAIL&p=PASSWORD



Real example :

php code :

$fs='http://api.filesonic.com/user?method=getInfo&u=xxxxxxx@gmail.com&p=xxxxxxxx';
$reply = file_get_contents($fs);

echo $reply;


output :
{"FSApi_User":{"getInfo":{"response":{"users":{"user":{"id":167xxxx,"email":"xxxxxxxxx@gmail.com","nickname":"xxxxxxxx","is_premium":false}}},"status":"success"
____________________________________________________
FSApi_Link

This API call allow you to get/set some informations related to the links. getInfo

Get links informations

Assumed response fields:
- id
- status (AVAILABLE, NOT_AVAILABLE, PRIVATE)

Response if status is AVAILABLE
- filename
- url
- size (in bytes)
- description (may be empty)
- is_password_protected (1 if password protected)
- is_premium_only (1 if premium only or 0)
- updated_on (format yyyy-mm-dd hh:ii:ss)

@important Too many links sent via url may cause browser limitation problem.
You should send large number of links via POST
@important Please Read: Howto Get Links Ids

@restriction The maximum number of ids is 100 per query.
The maximum length of all the ids is limited to 900

@param [ids] Can be an Array or a CSV

@return Array

@example http://api.filesonic.com/link?method=getInfo&ids=1234,1111,4444
@example http://api.filesonic.com/link?method=getInfo&ids[]=1234&ids[]=1111&ids[]=444


Real example :


php code :
$fs='http://api.filesonic.com/link?method=getInfo&ids=2255134814';
$reply = file_get_contents($fs);
echo $reply;


out put :
{"FSApi_Link":{"getInfo":{"response":{"links":[{"id":2255134814,"filename":"1847199143.rar","size":6927661,"description":"","is_password_protected":false,"is_premium_only":false,"updated_on":"2011-09-30 14:04:24","status":"AVAILABLE","url":"http:\/\/www.filesonic.com\/file\/2255134814"}]},"status":"success"}}}
--------------------------------------
MY target to learn

FSApi_Upload

FSApi_Download
 
7 comments
Found this post looking for a simple Filesonic API upload example (in php).
Couldnt find one so thought id post what I knocked up in case it helps anyone else.


PHP:
	$username = '******@gmail.com';
	$password = '*******';
	$file = 	'/your/file/path.jpg';
	
	
	$fs="http://api.filesonic.com/upload?method=getUploadUrl&format=json&u=$username&p=$password";
	$reply = file_get_contents($fs);	
	preg_match('#"url":"(.*?)".+"status":"(.+?)"#',$reply,$matches);
	if ($matches[2] == 'success')
	{
		$request_url = stripslashes($matches[1]);
        $post_params['files[]'] = '@'. $file;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $request_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
        $reply = curl_exec($ch);
        curl_close($ch);
		preg_match('#"url":"(.*?)".+"status":"(.+?)"#',$reply,$matches);
		if ($matches[2] == 'success')
			echo stripslashes($matches[1]);
		else print 'error';
	} else print 'error';
 
Found this post looking for a simple Filesonic API upload example (in php).
Couldnt find one so thought id post what I knocked up in case it helps anyone else.


PHP:
    $username = '******@gmail.com';
    $password = '*******';
    $file =     '/your/file/path.jpg';
    
    
    $fs="http://api.filesonic.com/upload?method=getUploadUrl&format=json&u=$username&p=$password";
    $reply = file_get_contents($fs);    
    preg_match('#"url":"(.*?)".+"status":"(.+?)"#',$reply,$matches);
    if ($matches[2] == 'success')
    {
        $request_url = stripslashes($matches[1]);
        $post_params['files[]'] = '@'. $file;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $request_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
        $reply = curl_exec($ch);
        curl_close($ch);
        preg_match('#"url":"(.*?)".+"status":"(.+?)"#',$reply,$matches);
        if ($matches[2] == 'success')
            echo stripslashes($matches[1]);
        else print 'error';
    } else print 'error';

This doesn't work. Anyone got hotfix?
 
This doesn't work. Anyone got hotfix?

The code works perfectly. If it’s not working for you it’s probably due to restrictions on your server regarding curl or a firewall if you’re running it locally. It successfully runs on my web-server once every hour. What exactly is your setup?
 
I am using localhost, firewall is off. I don't know what config options I should check.

But here is where your script fails:
After I use curl_getinfo($ch) just before the curl_close($ch)
I get this response:
http://codepad.org/kS5sH82x

As you can see, 'http_code' => int 0 and content_type is empty. Looks like curl fails.

Do you have any ideas pwdguy? Can you post your config.

EDIT: Maybe we need cookie?
 
Last edited:
Status
Not open for further replies.
Back
Top