www.google.com/apis/gadgets/gs.html
Terms and Conditions Search Gadgets Docs Search Getting Started Welcome to the Google Gadgets API! This document walks you through creating your first Google Gadget. This document is intended for people who want to use the Google 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.
You can put the URL for any gadget specification in the Add by URL text box, including ones that you or your friends write (as long as they are posted on a public web server). 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.
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. The Google 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.
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. Note: Gadgets were formerly called modules, which is why the word "Module" appears throughout the API. Writing Your Own Gadgets To get started writing your own gadgets, we recommend that you copy one of the examples and make a very simple change to it.
You can use the content directory to search for gadgets and add them to your homepage. To figure out what this URL should be, you may have to ask for help from your webmaster. Adding the Developer Gadget The developer gadget acts a "command center" for all of the gadgets on your homepage. In addition to listing all the gadgets that you're running, it lets you add, view, and manage gadgets. The developer gadget gives you features that you will need if you're doing gadget development. For example, it lets you add gadgets that are "broken," which is useful when you are actively changing a gadget.
Add to Google Developer Gadget In the developer gadget you can click on individual gadget links to view their XML specifications. This is a good way to see how other gadgets are implemented. You don't need to worry about advanced developer gadget features for now.
But one feature you may want to take advantage of right away is the Cached checkbox. You should uncheck Cached for gadgets while you are working on them. This lets you see your edits instead of the cached gadget. Hosting Gadgets If you don't have access to a public web server, you can host your gadgets using Google Page Creator.
If you are a new Google Page Creator user: The first time you use Google Page Creator, you must agree to the Terms and Conditions before you can go any further. After that, you are taken to a page that displays your default Google Page Creator home page in an editor (note that this home page is not related to your personalized homepage). From this page you can click Back to the Page Manager to go to the Page Manager. If you are not a new Google Page Creator user: When you log into Google Page Creator, the first page it displays is the Page Manager. The added file is listed in the "Uploaded stuff" area of the Page Manager. You can delete files by clicking their associated trash can icons. xml Remember: Gadgets are Public Remember that there is no such thing as a private gadget. Once you publish your gadget on a public website, people can find it and view it. Be sure not to include personal information, such as your telephone number or personal email address. Google encourages gadget authors to share their specifications.
There are some subtleties to avoid getting crawled by search engines: + Make sure your web server doesn't provide a file listing that includes your file (this also avoids users snooping). Creating a Gadget Spec Once you understand how to edit and publish gadgets, you're ready to include more advanced features in your gadget specifications. The XML gadget specification consists of 3 major parts: * Gadget Preferences.
It is where you specify the type of gadget, your programming logic, and often the HTML elements that determine the appearance of your gadget. Note: Within the XML attributes in a gadget spec, you need to "escape" (that is, properly encode) certain characters so that they will be interpreted correctly.
When writing a gadget, you should start with the <Content> section. Defining Content The <Content> section represents the "brains" of a gadget. The <Content> section defines the type of content, and either holds the content itself or has a link to external content. The <Content> section is where the gadget attributes and user preferences are combined with programming logic and formatting information to become a running gadget. The easiest way to create your gadget is to simply place HTML (and optionally, JavaScript or Flash) into the <Content> section.
Choosing a Content Type for other options relating to access control, remote hosting, using alternative scripting languages, and other topics. "></a> </div> > </Content> </Module> This is the running gadget: Defining User Preferences Some gadgets need to give users a way of supplying user-specific information. For example, a game gadget might allow users to enter a preferred level of difficulty. The user preferences (<UserPref>) section in the XML file describes the user input fields that are turned into user interface controls when the gadget runs. For example, this gadget displays a personal greeting based on the time of day. It lets users specify the following: * A name to use in the greeting. jpg"/> <UserPref name="mychoice" display_name="Show Photo?" datatype="bool" default_value="true"/> <UserPref name="mycolor" display_name="Color" default_value="Yellow" datatype="enum" > <EnumValue value="Red" /> <EnumValue value="Aqua" /> <EnumValue value="Lime" /> <EnumValue value="Yellow" /> <EnumValue value="Pink" /> <EnumValue value="Orange" /> <EnumValue value="White" /> </UserPref> Note the following: * Line 3 of the file contains the text title="Preferences for __UP_myname__".
If the user tries to run the gadget without supplying a value for this field, the user preferences edit box remains open until a value is provided. The list of EnumValues specifies the choices that appear in a drop-down menu in the user preferences edit box. Here is the JavaScript that displays the greeting for the gadget: <Content type="html"> <!
User preferences are accessed from your gadget using the user preferences JavaScript API, for example: <script type="text/javascript"> // Must be constructed using the __MODULE_ID__ token. It gets replaced // at runtime with the actual ID of your gadget.
User Preference Substitution Variables You can use a substitution variable of the format __UP_userpref__ in the <ModulePrefs> or <UserPref> sections, where userpref matches the name attribute of a user preference. When the gadget runs, the string value of the corresponding user preference is substituted for the variable, unescaped.
Defining Gadget Preferences The <ModulePrefs> section in the XML file specifies characteristics of the gadget, such as title, author, preferred sizing, and so on.
Gadget Scratch Pad Here's a scratch pad where you can create and test gadgets. The scratch pad preview feature currently ...
|