[facebook]

Description

Link: [facebook]
Author: Jason Huck
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Sep. 07, 2010
Updated: Jan. 01, 0001
More by this author...

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

Parameters

none


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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net