Please see http://www.opensocial.org/specs for the latest version of the OpenSocial specification.

Gadgets API Reference (v0.8)

This document describes the classes and methods in the gadgets.* namespace, some of which are feature-specific. For information on including features, see the Gadgets Specification.

Note: This API is not yet supported by the production instance of iGoogle, though it is available in the iGoogle sandbox. If you'd like to write a gadget for iGoogle, see the Gadgets API Reference.

Contents

Back to top

Type Conventions

This document uses the following conventions for types:

Array<T> or Array.<T>
An Array filled with only objects of type T. This convention is similar to Java generics.
Map<K, V> or Map.<K, V>
A JavaScript object with keys of type K that map to values of type V. Again, this convention is similar to Java generics. It's often used for opt_params variables.
static
A type marked with static class has no public or private constructor. In other words, the type is a namespace, not a class that can be instantiated to create objects. The fields and functions in such a type are also marked as static.
Boolean
A boolean value (not a Boolean object).
String
A string value (not a String object).

Back to top

Class gadgets.MiniMessage

SUMMARY DETAIL

MiniMessage class, used to create messages that will appear to the user within the gadget. Typical use cases:

Constructor Summary

gadgets.MiniMessage(opt_moduleId, opt_container)
Creates a MiniMessage.

Method Summary

HTMLElement createDismissibleMessage(message, opt_callback)
Creates a dismissible message with an [x] icon that allows users to dismiss the message.
HTMLElement createStaticMessage(message)
Creates a static message that can only be dismissed programmatically (by calling dismissMessage()).
HTMLElement createTimerMessage(message, seconds, opt_callback)
Creates a message that displays for the specified number of seconds.
dismissMessage(message)
Dismisses the specified message.

Constructor Detail

gadgets.MiniMessage

gadgets.MiniMessage(opt_moduleId, opt_container)

Method Detail

createDismissibleMessage

HTMLElement createDismissibleMessage(message, opt_callback)

createStaticMessage

HTMLElement createStaticMessage(message)

createTimerMessage

HTMLElement createTimerMessage(message, seconds, opt_callback)

dismissMessage

dismissMessage(message)

Back to top

Class gadgets.Prefs

SUMMARY DETAIL

Provides access to user preferences, module dimensions, and messages. Clients can access their preferences by constructing an instance of gadgets.Prefs and passing in their module ID. Example:

var prefs = new gadgets.Prefs();
var name = prefs.getString("name");
var lang = prefs.getLang();

Constructor Summary

gadgets.Prefs(opt_moduleId)
Creates a new Prefs object.

Method Summary

Array.<String> getArray(key)
Retrieves a preference as an array.
Boolean getBool(key)
Retrieves a preference as a boolean.
String getCountry()
Gets the current country, returned as ISO 3166-1 alpha-2 code.
Number getFloat(key)
Retrieves a preference as a floating-point value.
Number getInt(key)
Retrieves a preference as an integer.
String getLang()
Gets the current language the gadget should use when rendering, returned as a ISO 639-1 language code.
String, Number getModuleId()
Gets the module ID for the current instance.
String getMsg(key)
Fetches an unformatted message.
String getString(key)
Retrieves a preference as a string.
set(key, val)
Stores a preference.
setArray(key, val)
Stores an array preference.

Constructor Detail

gadgets.Prefs

gadgets.Prefs(opt_moduleId)

Method Detail

getArray

Array.<String> getArray(key)

getBool

Boolean getBool(key)

getCountry

String getCountry()

getFloat

Number getFloat(key)

getInt

Number getInt(key)

getLang

String getLang()

getModuleId

String, Number getModuleId()

getMsg

String getMsg(key)

getString

String getString(key)

set

set(key, val)

setArray

setArray(key, val)

Back to top

Class gadgets.Tab

SUMMARY DETAIL

Tab class for gadgets. You create tabs using the TabSet addTab() method. To get Tab objects, use the TabSet getSelectedTab() or getTabs() methods.

See also: TabSet

Method Summary

Function getCallback()
Returns the callback function that is executed when the tab is selected.
HTMLElement getContentContainer()
Returns the HTML element where the tab content is rendered.
Number getIndex()
Returns the tab's index.
String getName()
Returns the label of the tab as a string (may contain HTML).
HTMLElement getNameContainer()
Returns the HTML element that contains the tab's label.

Method Detail

getCallback

Function getCallback()

getContentContainer

HTMLElement getContentContainer()

getIndex

Number getIndex()

getName

String getName()

getNameContainer

HTMLElement getNameContainer()

Back to top

Class gadgets.TabSet

SUMMARY DETAIL

A class gadgets can use to make tabs.

Constructor Summary

gadgets.TabSet(opt_moduleId, opt_defaultTab, opt_container)
Creates a new TabSet object

Method Summary

String addTab(tabName, opt_params)
Adds a new tab based on the name-value pairs specified in opt_params.
alignTabs(align, opt_offset)
Sets the alignment of tabs.
displayTabs(display)
Shows or hides tabs and all associated content.
HTMLElement getHeaderContainer()
Returns the tab headers container element.
gadgets.Tab getSelectedTab()
Returns the currently selected tab object.
Array.<gadgets.Tab> getTabs()
Returns an array of all existing tab objects.
removeTab(tabIndex)
Removes a tab at tabIndex and all of its associated content.
setSelectedTab(tabIndex)
Selects the tab at tabIndex and fires the tab's callback function if it exists.
swapTabs(tabIndex1, tabIndex2)
Swaps the positions of tabs at tabIndex1 and tabIndex2.

Constructor Detail

gadgets.TabSet

gadgets.TabSet(opt_moduleId, opt_defaultTab, opt_container)

Method Detail

addTab

String addTab(tabName, opt_params)

alignTabs

alignTabs(align, opt_offset)

displayTabs

displayTabs(display)

getHeaderContainer

HTMLElement getHeaderContainer()

getSelectedTab

gadgets.Tab getSelectedTab()

getTabs

Array.<gadgets.Tab> getTabs()

removeTab

removeTab(tabIndex)

setSelectedTab

setSelectedTab(tabIndex)

swapTabs

swapTabs(tabIndex1, tabIndex2)

Back to top

Static Class gadgets.flash

SUMMARY DETAIL

Embeds Flash content in gadgets.

Method Summary

<static> Boolean embedCachedFlash()
Injects a cached Flash file into the DOM tree.
<static> Boolean embedFlash(swfUrl, swfContainer, swfVersion, opt_params)
Injects a Flash file into the DOM tree.
<static> Number getMajorVersion()
Detects Flash Player and its major version.

Method Detail

embedCachedFlash

<static> Boolean embedCachedFlash()

embedFlash

<static> Boolean embedFlash(swfUrl, swfContainer, swfVersion, opt_params)

getMajorVersion

<static> Number getMajorVersion()

Back to top

Static Class gadgets.io

SUMMARY DETAIL

Provides remote content retrieval functions.

Method Summary

<static> String encodeValues(fields)
Converts an input object into a URL-encoded data string.
<static> String getProxyUrl(url, opt_params)
Gets the proxy version of the passed-in URL.
<static> makeRequest(url, callback, opt_params)
Fetches content from the provided URL and feeds that content into the callback function.

Method Detail

encodeValues

<static> String encodeValues(fields)

getProxyUrl

<static> String getProxyUrl(url, opt_params)

makeRequest

<static> makeRequest(url, callback, opt_params)

Key management for gadgets.io.AuthorizationType.SIGNED

If a container uses public keys to sign requests, the container may choose to use either self-signed certificates or certificates signed by a well-known certificate authority. If a container does not distribute its OAuth signing key over HTTPS, it should use a certificate signed by a well-known certificate authority.

The commonName attribute of the certificate should match the hostname of the container server, and should also match the value of the oauth_consumer_key parameter specified in the request.

The container should make its public key available for download at a well-known location. The location https://container-hostname/opensocial/certificates/xoauth_public_keyvalue is recommended.

Recipients of signed requests must verify that the signature on the request is correct, and that the timestamp on the request is within a reasonable time window. A time window of 5 minutes before and after the current time is recommended.

Recipients of signed requests may use the oauth_consumer_key and xoauth_public_key parameters to automatically detect when a container deploys new certificates. If the container deploys certificates at a well-known location, the recipient may automatically download the new certificate. Recipients that automatically download new certificates should cache the resulting certificates.

If a container's certificate is not downloaded from https://container-hostname, the recipient should verify that the certificate is signed by a well-known certificate authority before trusting the certificate.

OAuth authorization

If opt_params[gadgets.io.RequestParameters.AUTHORIZATION] is set to gadgets.io.AuthorizationType.OAUTH, the container needs to use OAuth to gain access to the resource specified in the request. This may require that the gadget obtain the user's content by directing the user to the service provider to gain access.

Additional parameters

The following additional parameters may be specified in opt_params:

gadgets.io.RequestParameters.OAUTH_SERVICE_NAME
The nickname the gadget uses to refer to the OAuth <Service> element from its XML spec. If unspecified, defaults to "".
gadgets.io.RequestParameters.OAUTH_TOKEN_NAME
The nickname the gadget uses to refer to an OAuth token granting access to a particular resources. If unspecified, defaults to "". Gadgets can use multiple token names if they have access to multiple resources from the same service provider. For example, a gadget with access to a contact list and a calendar might use a token name of "contacts" to use the contact list token, and a contact list of "calendar" to use the calendar token.
gadgets.io.RequestParameters.OAUTH_REQUEST_TOKEN
A service provider may be able to automatically provision a gadget with a request token that is preapproved for access to a resource. The gadget can use that token with the OAUTH_REQUEST_TOKEN parameter. This parameter is optional.
gadgets.io.RequestParameters.OAUTH_REQUEST_TOKEN_SECRET
The secret corresponding to a preapproved request token. This parameter is optional.

If OAuth is used, the container should execute the OAuth protocol on behalf of the gadget. If the gadget has not registered a consumer key for use with this service provider, the container may choose to use a default RSA signing key corresponding to a well-known certificate to sign requests. If the container uses a default consumer key, it will include an additional OAuth parameter xoauth_app_url that identifies the gadget making the request.

The callback parameter

The makeRequest() callback parameter is passed a javascript object with several OAuth-specific fields in addition to the normal values returned by makeRequest():

"oauthApprovalUrl"
If this value is specified, the user needs to visit an external page to approve the gadget's request to access data. Use of a pop-up window to direct the user to the external page is recommended. Once the user has approved access, the gadget can repeat the makeRequest call to retrieve the data.
"oauthError"
If this value is specified, it indicates an OAuth-related error occurred. The value will be one of a set of string constants that can be used for programmatically detecting errors. The constants are undefined for opensocial-0.8, but implementers should attempt to agree on a set of useful constant values for standardization in opensocial-0.9.
"oauthErrorText"
If this value is specified, it indicates an OAuth-related error occurred. The value is free-form text that can be used to provide debugging information for gadget developers.

Back to top

Static Class gadgets.io.AuthorizationType

SUMMARY DETAIL

Used by RequestParameters.

Field Summary

<static> object NONE
No authorization.
<static> object OAUTH
The container will use OAuth for authentication.
<static> object SIGNED
The request will be signed by the container.

Field Detail

NONE

<static> object NONE

OAUTH

<static> object OAUTH

SIGNED

<static> object SIGNED

Back to top

Static Class gadgets.io.ContentType

SUMMARY DETAIL

Used by RequestParameters.

Field Summary

<static> object DOM
Returns a DOM object; used for fetching XML.
<static> object FEED
Returns a JSON representation of an RSS or Atom feed.
<static> object JSON
Returns a JSON object.
<static> object TEXT
Returns text; used for fetching HTML.

Field Detail

DOM

<static> object DOM

FEED

<static> object FEED

JSON

<static> object JSON

TEXT

<static> object TEXT

Back to top

Static Class gadgets.io.MethodType

SUMMARY DETAIL

Defines values for RequestParameters.METHOD.

Field Summary

<static> object DELETE
Container support for this method type is OPTIONAL.
<static> object GET
The default type.
<static> object HEAD
Container support for this method type is OPTIONAL.
<static> object POST
Container support for this method type is OPTIONAL.
<static> object PUT
Container support for this method type is OPTIONAL.

Field Detail

DELETE

<static> object DELETE

GET

<static> object GET

HEAD

<static> object HEAD

POST

<static> object POST

PUT

<static> object PUT

Back to top

Static Class gadgets.io.ProxyUrlRequestParameters

SUMMARY DETAIL

Used by gadgets.io.getProxyUrl() method.

Field Summary

<static> object REFRESH_INTERVAL
Attempt to use content caching.

Field Detail

REFRESH_INTERVAL

<static> object REFRESH_INTERVAL

Back to top

Static Class gadgets.io.RequestParameters

SUMMARY DETAIL

Used by the gadgets.io.makeRequest() method.

Field Summary

<static> object AUTHORIZATION
The type of authentication to use when fetching the content; defaults to AuthorizationType.NONE.
<static> object CONTENT_TYPE
The type of content that lives at the URL; defaults to ContentType.TEXT.
<static> object GET_SUMMARIES
If the content is a feed, whether to fetch summaries for that feed; defaults to false.
<static> object HEADERS
The HTTP headers to send to the URL; defaults to null.
<static> object METHOD
The method to use when fetching content from the URL; defaults to MethodType.GET.
<static> object NUM_ENTRIES
If the content is a feed, the number of entries to fetch; defaults to 3.
<static> object POST_DATA
The data to send to the URL using the POST method; defaults to null.

Field Detail

AUTHORIZATION

<static> object AUTHORIZATION

CONTENT_TYPE

<static> object CONTENT_TYPE

GET_SUMMARIES

<static> object GET_SUMMARIES

HEADERS

<static> object HEADERS

METHOD

<static> object METHOD

NUM_ENTRIES

<static> object NUM_ENTRIES

POST_DATA

<static> object POST_DATA

Back to top

Static Class gadgets.json

SUMMARY DETAIL

Provides operations for translating objects to and from JSON.

Method Summary

<static> Object parse(text)
Parses a JSON string, producing a JavaScript value.
<static> String stringify(v)
Converts a JavaScript value to a JSON string.

Method Detail

parse

<static> Object parse(text)

stringify

<static> String stringify(v)

Back to top

Static Class gadgets.pubsub

SUMMARY DETAIL

Provides operations for publishing and subscribing to message channels.

Method Summary

<static> publish(channelName, message)
Publishes a string-type message to a channel.
<static> subscribe(channelName, callback)
Subscribes a gadget to a message channel.
<static> unsubscribe(channelName)
Unsubscribes the gadget from a message channel.

Method Detail

publish

<static> publish(channelName, message)

subscribe

<static> subscribe(channelName, callback)

unsubscribe

<static> unsubscribe(channelName)

Back to top

Static Class gadgets.rpc

SUMMARY DETAIL

Provides operations for making remote procedure calls for gadget-to-container, container-to-gadget, and gadget-to-gadget communication.

Method Summary

<static> call(targetId, serviceName, callback, var_args)
Calls an RPC service.
<static> register(serviceName, handler)
Registers an RPC service.
<static> registerDefault(handler)
Registers a default service handler to process all unknown remote procedure calls, which fail silently by default.
<static> unregister(serviceName)
Unregisters an RPC service.
<static> unregisterDefault()
Unregisters the default service handler.

Method Detail

call

<static> call(targetId, serviceName, callback, var_args)

register

<static> register(serviceName, handler)

registerDefault

<static> registerDefault(handler)

unregister

<static> unregister(serviceName)

unregisterDefault

<static> unregisterDefault()

Back to top

Static Class gadgets.skins

SUMMARY DETAIL

Provides operations for getting display information about the currently shown skin.

Method Summary

<static> String getProperty(propertyKey)
Fetches the display property mapped to the given key.

Method Detail

getProperty

<static> String getProperty(propertyKey)

Back to top

Static Class gadgets.skins.Property

SUMMARY DETAIL

All of the display values that can be fetched and used in the gadgets UI. These are the supported keys for the gadgets.skins.getProperty() method.

Field Summary

<static> object ANCHOR_COLOR
The color that anchor tags should use.
<static> object BG_COLOR
The color of the background of the gadget.
<static> object BG_IMAGE
An image to use in the background of the gadget.
<static> object FONT_COLOR
The color in which the main font should be rendered.

Field Detail

ANCHOR_COLOR

<static> object ANCHOR_COLOR

BG_COLOR

<static> object BG_COLOR

BG_IMAGE

<static> object BG_IMAGE

FONT_COLOR

<static> object FONT_COLOR

Back to top

Static Class gadgets.util

SUMMARY DETAIL

Provides general-purpose utility functions.

Method Summary

<static> String escapeString(str)
Escapes the input using HTML entities to make it safer.
<static> Object getFeatureParameters(feature)
Returns the value of parameters for this feature.
<static> Boolean hasFeature(feature)
Returns whether the specified feature is supported.
<static> registerOnLoadHandler(callback)
Registers an onload handler ? a function that's executed when the gadget loads.
<static> String unescapeString(str)
Reverses escapeString

Method Detail

escapeString

<static> String escapeString(str)

getFeatureParameters

<static> Object getFeatureParameters(feature)

hasFeature

<static> Boolean hasFeature(feature)

registerOnLoadHandler

<static> registerOnLoadHandler(callback)

unescapeString

<static> String unescapeString(str)

Back to top

Static Class gadgets.views

SUMMARY DETAIL

Provides operations for dealing with views.

See also: gadgets.views.View

Method Summary

<static> String bind(urlTemplate, environment)
Binds a URL template with variables in the passed environment to produce a URL string.
<static> gadgets.views.View getCurrentView()
Returns the current view.
<static> Map.<String, String> getParams()
Returns the parameters passed into this gadget for this view.
<static> Map<gadgets.views.ViewType, String, gadgets.views.View> getSupportedViews()
Returns a map of all the supported views.
<static> requestNavigateTo(view, opt_params, opt_ownerId)
Attempts to navigate to this gadget in a different view.

Method Detail

bind

<static> String bind(urlTemplate, environment)

getCurrentView

<static> gadgets.views.View getCurrentView()

getParams

<static> Map.<String, String> getParams()

getSupportedViews

<static> Map<gadgets.views.ViewType, String, gadgets.views.View> getSupportedViews()

requestNavigateTo

<static> requestNavigateTo(view, opt_params, opt_ownerId)

Back to top

Class gadgets.views.View

SUMMARY DETAIL

Base interface for all view objects.

Method Summary

String bind(environment)
Binds the view's URL template with variables in the passed environment to produce a URL string.
gadgets.views.ViewType, String getName()
Returns the name of this view.
String getUrlTemplate()
Returns a string URI template conforming to the IETF spec draft with variables for substitution.
boolean isOnlyVisibleGadget()
Returns true if the gadget is the only visible gadget in this view.

Method Detail

bind

String bind(environment)

getName

gadgets.views.ViewType, String getName()

getUrlTemplate

String getUrlTemplate()

isOnlyVisibleGadget

boolean isOnlyVisibleGadget()

Back to top

Static Class gadgets.views.ViewType

SUMMARY DETAIL

Used by Views.

Field Summary

<static> object CANVAS
A view where the gadget is displayed in a very large mode.
<static> object HOME
A view where the gadget is displayed in a small area usually on a page with other gadgets.
<static> object PREVIEW
A demo view of the gadget.
<static> object PROFILE
A view where the gadget is displayed in a small area usually on a page with other gadgets.

Field Detail

CANVAS

<static> object CANVAS

HOME

<static> object HOME

PREVIEW

<static> object PREVIEW

PROFILE

<static> object PROFILE

Back to top

Static Class gadgets.window

SUMMARY DETAIL

Provides operations for getting information about and modifying the window the gadget is placed in.

Method Summary

<static> adjustHeight(opt_height)
Adjusts the gadget height.
<static> Object getViewportDimensions()
Detects the inner dimensions of a frame.
<static> setTitle(title)
Sets the gadget title.

Method Detail

adjustHeight

<static> adjustHeight(opt_height)

getViewportDimensions

<static> Object getViewportDimensions()

setTitle

<static> setTitle(title)

The copyrights in this specification are licensed under the Creative Commons Attribution 2.5 license | Terms of Service