Lasso Soft Inc. > Home

[facebook]

Linkfacebook
AuthorJason Huck
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted07 Sep 2010
Updated07 Sep 2010
More by this author...

Description

This is a simple wrapper for the Facebook API. Requires [decode_json] or [xml_tree], depending on your usage.

Sample Usage

// trust me, you don't really want to do this ;)

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_type(
	'facebook',
	-description='Lasso wrapper for the Facebook API.'
);
	local(
		'api_key' = null,
		'secret' = null,
		'v' = 1.0,
		'format' = 'JSON'
	);
	
	define_tag(
		'oncreate', 
		-req='api_key',
		-req='secret',
		-opt='format'
	);
		self->'api_key' = #api_key;
		self->'secret' = #secret;
		local_defined('format') ? self->'format' = #format;
	/define_tag;

	define_tag('generate_sig', -req='params', -copy, -encodenone);
		local('out') = string;	
		#params->sort;
		
		iterate(#params, local('i'));
			#out += #i->first + '=' + #i->second;
		/iterate;
		
		#out += self->'secret';			
		return(encrypt_md5(#out));
	/define_tag;
	
	define_tag('send', -req='methodparams', -copy, -encodenone);
		local('postparams') = array(
			'api_key' = self->'api_key',
			'secret' = self->'secret',
			'v' = self->'v',
			'format' = self->'format',
			'call_id' = date_msec
		);
		
		#postparams->merge(#methodparams);
		#postparams->sort;			
		local('sig') = self->generate_sig(#postparams);			
		#postparams->insert('sig' = #sig);			
		local('response') = string;
	
		protect;
			#response = string(include_url(
				'http://api.facebook.com/restserver.php',
				-sendmimeheaders=(: 'Content-Type' = 'application/x-www-form-urlencoded'),
				-postparams=#postparams,
				-timeout=15,
				-connecttimeout=15
			))->trim&;
			
			if(self->'format' == 'JSON');
				#response = decode_json(#response);
			else;
				#response = xml_tree(#response);
			/if;
			
			handle_error;
				#response = error_msg;
			/handle_error;
		/protect;
		
		return(#response);
	/define_tag;
	
	define_tag('_unknowntag');
		local('methodparams') = array;
		
		iterate(params, local('i'));
			local('k') = string(#i->first)->removeleading('-')&;
			local('v') = #i->second;
			#methodparams->insert(#k = #v);
		/iterate;
		
		#methodparams->insert('method' = tag_name);
		return(self->send(#methodparams));
	/define_tag;
/define_type;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft