You are here: Docs Technical Documentation Clearspring APIs In-Widget API Widget

Widget

Widget Management

widget provides functions for registering and updating registered widgets. It also allows you to reconfigure a widget at run-time (e.g., to use your own preferences engine).

 

Contents

 

API Reference

Name Type Description
widget.configure method Reloads a running widget with new configuration; new configuration will propagate with any shares, but will not persist past session
widget.register method Register a new widget. Not so much for registering mass numbers of widgets, as you're capped at 50 per day, but rather so you don't have to ever manually register a widget using our console if you'd prefer to just work with our API suite.
widget.update method Update a registered widget. For changing a widget's content on the fly.

widget.configure

method

Reloads a running widget with new configuration; new configuration will propagate with any shares, but will not persist past current session.

Parameters
Name Type Required Purpose
Configuration object yes Maps parameter names to new values; e.g., if 'foo' and 'bar' are parameters, you might pass {foo: 'newfoo'} to update foo. bar will remain unchanged.
Return
None
Example Usage

AS2

// Sets 'color' to red; sets 'number' to 6.
// Widget will be reloaded to display the new configuration, 
// but will still count as the same user interaction session.
_level0.cs.widget.configure({color: 0xff0000, number: 6});

AS3

// Sets 'color' to red; sets 'number' to 6.
// Widget will be reloaded to display the new configuration, 
// but will still count as the same user interaction session.
_api.widget.configure({color: 0xff0000, number: 6});

JavaScript

// Note: Only available within JS kernel
//
// Sets 'color' to red; sets 'number' to 6.
// Widget will be reloaded to display the new configuration, 
// but will still count as the same user interaction session.
_api.widget.configure({color: 0xff0000, number: 6});
back to table

widget.register

method

Register a new widget. Not so much for registering mass numbers of widgets, as you're capped at 50 per day, but rather so you don't have to ever manually register a widget using our console if you'd prefer to just work with our API suite.

N.B.: We strongly discourage making this call in a production widget, as no matter how obfuscated you make it, your widget code can ultimately be compromised once it's in the wild due to the interpreted nature of both Flash and JavaScript. Protect your user ID; only make this call from within a trusted environment.

Parameters
Name Type Required Purpose
User ID string yes Clearspring user ID; available when logged in under Settings tab.
Widget name string yes Name of widget. For internal reporting and for publishing to third parties like the iGoogle Gallery.
Optional parameters object yes For simplicity, any of the following optional parameters may be specified in a single object; e.g., {language: 'js'}
  • language (string) — one of 'as2', 'as3', or 'js'. Defaults to the language of the current running kernel or container.
  • content (string) — HTML content representing the newly registered widget. Could be an object tag, could be arbitrary HTML.
  • config (object) — object hash of configuration parameters and their defaults (e.g., {color: 'red', number: 6})
callback function yes The first parameter is zero iff. the call succeeded; a nonzero status indicates an error. The second parameter contains a native object mapping returned keys to their url-encoded values. Interesting returned parameters include widgetId, a unique ID for your widget in our system, and placementId, a seed placement ID for your widget sharing.
Return
None
Example Usage

AS2

function callback(status:Number, result:Object):Void
{
	if (status)
	{
		trace('An error occurred: ' + status);
	}
	else
	{
		trace('Successfully registered widget; widget ID=' + result.widgetId);
	}
}

_level0.cs.widget.register('userid', 
			   'my first widget', 
			   {content: '<h1>an exciting header</h1>"}, 
			   callback);
	

AS3

function callback(status:Number, result:Object):Void
{
	if (status)
	{
		trace('An error occurred: ' + status);
	}
	else
	{
		trace('Successfully registered widget; widget ID=' + result.widgetId);
	}
}

_api.widget.register('userid', 
		     'my first widget', 
		     {content: '<h1>an exciting header</h1>"}, 
		     callback);

JavaScript

function callback(status, result):Void
{
	if (status)
	{
		alert('An error occurred: ' + status);
	}
	else
	{
		alert('Successfully registered widget; widget ID=' + result.widgetId);
	}
}

_api.widget.register('userid', 
	 	     'my first widget', 
		     {content: '<h1>an exciting header</h1>"}, 
		     callback);
back to table

widget.update

method

Update a registered widget. For changing a widget's content on the fly.

N.B.: We strongly discourage making this call in a production widget, as no matter how obfuscated you make it, your widget code can ultimately be compromised once it's in the wild due to the interpreted nature of both Flash and JavaScript. Protect your user ID; only make this call from within a trusted environment.

Parameters
Name Type Required Purpose
user ID String yes Clearspring user ID; available when logged in under Settings tab.
widget ID String yes Widget ID (available in our Widget Console; also returned in calls to widget.register.
optional parameters Object yes For simplicity, any of the following optional parameters may be specified in a single object; e.g., {language: 'js'}
  • language (string) — one of 'as2', 'as3', or 'js'. Defaults to the language of the current running kernel or container.
  • content (string) — new HTML content for the widget. Could be an object tag, could be arbitrary HTML.
  • width (number) — width of widget, in pixels; only needed when using our share services
  • height (number) — height of widget, in pixels; only needed when using our share services
callback function yes The first parameter is zero iff. the call succeeded; a nonzero status indicates an error. The second parameter contains a native object mapping returned keys to their url-encoded values. Interesting returned parameters include widgetId, a unique ID for your widget in our system, and placementId, a seed placement ID for your widget sharing.
Return
None
Example Usage

AS2

function callback(status:Number, result:Object):Void
{
	if (status)
	{
		trace('An error occurred: ' + status);
	}
	else
	{
		trace('Successfully updated widget');
	}
}

_level0.cs.widget.update('userid', 
			 'widgetid', 
                         {content: '<h1>an <strong>even more</strong> exciting header</h1>"}, 
			 callback);

AS3

function callback(status:Number, result:Object):Void
{
	if (status)
	{
		trace('An error occurred: ' + status);
	}
	else
	{
		trace('Successfully updated widget');
	}
}

_api.widget.update('userid', 
 	           'widgetid', 
                   {content: '<h1>an <strong>even more</strong> exciting header</h1>"}, 
		   callback);

JavaScript

function callback(status, result):Void
{
	if (status)
	{
		alert('An error occurred: ' + status);
	}
	else
	{
		alert('Successfully updated widget');
	}
}

_api.widget.update('userid', 
 	           'widgetid', 
                   {content: '<h1>an <strong>even more</strong> exciting header</h1>"}, 
		   callback);
back to table


Error Codes

Code Description
2300Catastrophic failure
2301Invalid input variables
2302Unknown command
2303Unauthorized access
2304Invalid authorization key
2370Invalid user ID specified
2371Invalid widget name specified
2372Unsupported language type
2373Widget registration limit exceeded