We're sorry, but this discussion has just been closed to further replies.
An OpenSocial Gadget is simply a small HTML+Javascript application that runs on a site, or "container", that supports the OpenSocial JavaScript API. Any Ning network is such a container.
With Ning's support for OpenSocial, and this guide, you can try your hand at creating OpenSocial Gadgets that can then run with relatively minor changes (or unchanged) on other containers.
API Scope
As of version 0.5, there are three primary areas of functionality in the OpenSocial API:
As long as your Gadget uses only these functions from the API, it should run unchanged across all conformant containers. Additionally, some containers such as Ning may implement some key functions supported by other containers, such as iGoogle or Orkut, to increase compatibility and simplify deployment for application developers.
For detailed information, see the API Reference.
Here is one of the most basic Gadgets you can write:
<?xml version="1.0" encoding="UTF-8" ?><Module><ModulePrefs title="Hello World Example"> <Require feature="opensocial-0.5"/> </ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
function sayHello() {
document.getElementById('message').innerHTML = 'Hello World!';
};
opensocial.registerOnloadHandler(sayHello);
</script>
<div id="message"> </div>
]]>
</Content>
</Module>
This example is a basic 'Hello World!' that goes beyond simply outputting text, to use an onLoadHandler call, in the form of opensocial.registerOnloadHandler(sayHello); which will be called as soon as the page loads. When this happens the sayHello function will be called, retrieving the DIV and setting the text to the appropriate value.
Inserting the Gadget into your profile for testing
Testing is easy -- you can simply save your gadget as a file in your network (through SFTP), in a (new) directory opensocial, with the name for example helloworld.xml. Then you can reference it by typing http://networkname.ning.com/opensocial/helloworld.xml into the URL box of your profile page, and presto! Your first opensocial gadget should be up and running.Tags: hello world, opensocial
Replies are closed for this discussion.
© 2009 Created by Ning Developer Admin