Gadgets API

Getting Started: gadgets.* API

Welcome to the gadgets API! To learn more about different types of gadgets and where they run, see the gadgets API Overview.

This developers guide is intended for people who want to use the gadgets API to write gadgets. Gadgets are so easy to create that they are a good starting point if you are just learning about web programming.

Contents

  1. "Hello, World"
  2. What's In a Gadget?
  3. Where to Go From Here

"Hello, World"

The simplest gadget is just a few lines of code. This gadget displays the message "Hello, world!":

<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs title="hello world example" />
<Content type="html">
<![CDATA[ Hello, world! ]]> </Content>
</Module>

Note the following about the "Hello World" example:

  • Gadgets are specified in XML. The first line is the standard way to start an XML file. This must be the first line in the file.
  • The <Module> tag indicates that this XML file contains a gadget.
  • The <ModulePrefs> tag contains information about the gadget such as its title, description, author, and other optional features.
  • The line <Content type="html"> indicates that the gadget's content type is HTML.
  • <![CDATA[ ...insert HTML here... ]]> is used to enclose HTML when a gadget's content type is html. It tells the gadget parser that the text within the CDATA section should not be treated as XML. The CDATA section typically contains HTML and JavaScript.
  • </Content> signifies the end of the Content section.
  • </Module> signifies the end of the gadget definition.

What's In a Gadget?

The gadgets API consists of a few simple building blocks: XML, HTML, and JavaScript. To get started, all you need is a basic understanding of HTML. We will teach you all you need to know about XML to write gadgets. Later, as you write more sophisticated gadgets, you will probably want to learn some JavaScript if you're not familiar with it already.

XML is a general purpose markup language. It describes structured data in a way that both humans and computers can read and write.

XML is the language you use to write gadget specifications. A gadget is simply an XML file, placed somewhere on the internet where Google can find it. The XML file that specifies a gadget contains instructions on how to process and render the gadget. The XML file can contain all of the data and code for the gadget, or it can have references (URLs) for where to find the rest of the elements.

HTML is the markup language used to format pages on the internet. The static content of a gadget is typically written in HTML. HTML looks similar to XML, but it's used to format web documents rather than to describe structured data.

JavaScript is a scripting language you can use to add dynamic behavior to your gadgets.

Where to Go From Here

For general gadget programming information, go to Writing Your Own Gadgets. From there you can go to Development Fundamentals, or back to the documentation home page for an overview of sections and topics.

If you're interested in developing OpenSocial gadgets, here are a few places to start getting some hands-on experience:

If you're interested in developing gadgets for Google Apps, the following guides will help you get started writing gadgets for the different Google Apps containers:

Back to top

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.