Lasso Soft Inc. > Home

[google_clientlogin]

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

Description

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

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.

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

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