[google_clientlogin]

Description

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

Implements the Client Login method to retrieve authentication tokens for Google Data APIs. Requires [dictionary].

Parameters

none


Sample Usage

// get a token via Client Login
var('token' = google_clientlogin(
	-Email='foo@foobar.com',
	-Passwd='sooperseekrit',
	-service='analytics'
));	

// create an object to interface with Google Analytics
var('gaData' = google_analyticsDataExport($token));

// get information about your Analytics account	
$gaData->getAccountData( -v=2, -prettyprint=true);	

// get the ID of a specific site
var('id') = $gaData->getTableIDByTitle('www.foobar.com');

// visits by browser & version for the past 30 days
var('reportData') = $gaData->getReportData(
	-ids=$id,
	-dimensions='ga:browser,ga:browserVersion',
	-metrics='ga:visits',
	-sort='-ga:visits',
	-startdate=date->subtract( -day=30)&,
	-enddate=date,
	-prettyprint=true
);
						

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
define_tag(
	'clientlogin',
	-namespace='google_',
	-opt='accountType',
	-req='Email',
	-req='Passwd',
	-req='service',
	-opt='source',
	-priority='replace',
	-encodenone,
	-description='Implements the Client Login method to retrieve authentication tokens for Google Data APIs.'
);	
	local('post') = array;
	
	iterate(params, local('i'));
		#i->isa('pair') ? #post->insert(string(#i->first)->removeleading('-')& = #i->second);
	/iterate;

	!local_defined('accountType') ? #post->insert('accountType' = 'HOSTED_OR_GOOGLE');
	!local_defined('source') ? #post->insert('source' = 'LassoSoft-Lasso-' + lasso_version( -lassoversion));
	
	protect;
		handle_error;
			local('response') = error_msg;
		/handle_error;
	
		local('response') = string(include_url(
			'https://www.google.com/accounts/ClientLogin',
			-postparams=#post,
			-timeout=30,
			-connecttimeout=30
		));
	/protect;
	
	!#response->beginswith('SID=') || !#response->size ? return('Invalid response.');
	
	// normalize line endings
	#response->replace('\r\n','\n')&replace('\r','\n');
	
	local('lines') = #response->split('\n');
	
	local('out') = dictionary;
	
	iterate(#lines, local('i'));
		!#i->size ? loop_continue;
	
		local('d') = @#i->split('=');
	
		local(
			'n' = #d->first,
			'v' = #d->second
		);
		
		#out->insert(#n = #v);
	/iterate;
	
	return(#out);
/define_tag;

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net