Coding, is? Fun!

Wednesday, September 24, 2008

What is OpenSocial?

The OpenSocial standard is currently at version 0.8. Already, it has been implemented by many social networking sites such as Friendster, Hi5 and Orkut. What does the standard mean?
In 2007, Facebook.com came out with an API and a platform for delivering widgets. A widget can be a word game, or a set of friends sharing movie reviews. Facebook followed a fairly complex model to render such widgets, and let them access facebook's social API.
But facebook widgets work only with facebook. They have to be basically rewritten to work with Orkut or other social sites.
Later in 2007, Google released the OpenSocial standard. That standard provides a spec for social networking sites (on the one hand) and widget writers (on the other) to implement. If sites Orkut and Friendster implement the OpenSocial standard, then a widget that works in Orkut will work with Friendster with no rewriting.
As with any standard, OpenSocial is based upon an abstraction of the services provided by a social network. Google also leveraged its existing Gadget spec (Google Gadgets) and added OpenSocial as a "feature" of gadgets.

Google Gadgets
Google gadgets are based upon the gadget spec. The gadget writer creates a gadget definition (which is in XML). This definition contains (among other things) Javascript code that can be called from the browser.
In a typical scenario, the gadget definition is written and is available in a public url - http://www.mygadget.com/mygadget.xml.
The gadget container is the host that is going to display the gadget. That site can be http://www.myhost.com. When you hit the host page, it will send a request to the gadget server, passing in the url of the gadget xml (in this case,http://www.mygadget.com/mygadget.xml). Google has a freely hosted gadget server called gmodules.com. There is also an open source project called Shindig that provides the code for a gadget server. The gadget server does the heavy lifting of translating the gadget definition to HTML that can be rendered on the browser. Among other things, the gadget definition provides localized "message bundles" for getting localized strings. A gadget can ask for different "features" from the gadget server.

Thus Google gadgets can be run in your website, provided you have a gadget server available.

Open Social
Google built Open Social as one of the features of the gadget server.
In the google gadget example above, there are three servers involved - the gadget definition host,the gadget server and the gadget container. The gadget container, in social networks, is a social container. For example, the social container knows who the current user is, his profile information, who his friends are and what his activities are. Abstractly, these are modelled as a set of social API. The social container renders the gadget and then provides social API services to it.
Take the case of Orkut - Orkut contains social data about you. In its profile pages and canvas pages, it renders applications or "widgets" These widgets are rendered using gmodules.com as the gadget server. The widget definitions are hosted in different third party web servers.
Orkut provides its social API to the widget by exposing Javascript functions.
Because these Javascript functions and their namespaces are a OpenSocial standrad, the same widget can work in any OpenSocial compliant website, such as Hi5 or Friendster.

If you are writing a widget you should refer to the gadget spec and the open social spec. Let us say a sample widget allows you to send messages to all your friends in a particular network. That widget will call a OpenSocial API function to get the list of friends and show them to you. It will call a different OpenSocial API function to send messages to the friends' inbox. Both these functions are available via the Javascript API.

A sample gadget definition is below:
<xml version="1.0" encoding="UTF-8" >
<Module>
<ModulePrefs title="List Friends Example>
<Require feature="opensocial-0.7"/>
</ModulePrefs>
<Content type="html>
<![CDATA[
<script type="text/javascript>
/** * Request for friend information. */ function getData() { var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer'); req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS), 'viewerFriends'); req.send(onLoadFriends); };
/** * Parses the response to the friend information request and generates * html to list the friends along with their display name. * * @param {Object} dataResponse Friend information that was requested. */ function onLoadFriends(dataResponse) { var viewer = dataResponse.get('viewer').getData(); var html = 'Friends of ' + viewer.getDisplayName(); html += ':
    '; var viewerFriends = dataResponse.get('viewerFriends').getData(); viewerFriends.each(function(person) { html += '
  • ' + person.getDisplayName() + '
  • '; }); html += '
'; document.getElementById('message').innerHTML = html; };
gadgets.util.registerOnLoadHandler(getData);
<script>
<div id="message">
</div>]]>
<Content>
</Module>

If you are a social network, and you want to implement OpenSocial, then you have to do the following:
- Download, install and run Shindig (there is a PHP and Java version). That will be your gadget server - you can, of course, implement your own gadget server, by going through the gadget and open social spec.
- Implement the Javascript API by making calls back to your social network database from the browser. Implement this in a library and have it included in your gadget rendering page
- Implement a set of hosting pages for the gadgets (typically using iframes) so that the request for the gadget goes through the gadget server.
- Implement an authorization scheme.
- Implement a set of pages for searching, adding and removing widgets from a user's profile.

In conclusion, OpenSocial is an abstraction of the social API of a container and the gadget rendering modules of any widget.

Labels:

How To Blog

This is my 51st post in this blog. I thought it should be about what I have learnt about blogging.
I will cover the following in this entry:
- How to start a Blog and some technical tips
- Why would you blog? What is the purpose of a blog? Is it necessary to start one? Is it a fad? What do we write about? How often?
The opinions are strictly based on my experiences.
I am not going to define a blog and all that. Please read Wikipedia's excellent entries on that here.

How To Start a Blog

What you need is a personal blog that you can use. This personal blog will
- allow you to manage all your "posts" or entries
- allow you to create new posts
- allow you to manage "templates" for your blog - that is your background color, layout, top banner and such things.
- allow you to manage comments in your own blog, so that you can delete them if offensive.
- manage history in your blog by archiving old blogs

Wordpress.com, LiveJournal.com, Blogger.com and many other sites allow you to do most of the above. The assumption here is that you want a public blog. Some blogging sites also allow you to create members only blogs. You can create a blog and invite a set of people to view it. Noone else will have access. Corporations also have blogs in their local network for knowledge management.
There are also several blogging sites that are domain specific - for example, DailyKos.com is an American political blogging site. Your audience are mostly looking for political commentary in such a site - they may not be interested in your love poetry.
The choice of a blogging site is, thus, guided by your interests. If all you are interested is in writing about Microsoft technologies, then there are several sites specific to that purpose. Some bloggers (like me) maintain several blogs at different sites. That makes it slightly difficult to manage your posts but targeted audience reach may be better.
One important consideration is multi-language support. There are several sites (including blogger.com) that provide support for Unicode - thus if you want to write in Tamil, you need not create your own site from scratch.
Most blogging sites allow you to embed images and videos. You can effectively build a corporate style article using a blogging site. Check for such features.
Most sites provide steps to create a blog that are really simple. Generally,
- create a username, password and a profile. Depending upon your nature, you may want more or less detail in your blog profile. Be aware that people across the internet, who do not know you, may like/dislike your opinions and may come after you. On the other hand, in case of a technical/professional blog particularly, you may want people to know you for your skills. Choose carefully what information you reveal.
- choose a template. In my blog, the orange color top banner was picked up by me, along with the layout. I have a different color in my technical blog. When you choose a template, I beg you, please do not pick white text on a dark background. It is tempting, but the way computer monitors work, your site will hurt people's eyes.

That is it. After this, you can go to your dashboard and start typing a blog any time.

Apart from the blog itself, you may be interested in knowing how many people visit, and also make your blog searchable. My articles on my Coorg trip, Ilayaraja's music and others still attract traffic mainly because people reach them through searches. How do you measure number of people visiting; what is popular; how to get attention? How do you know who links to your articles?
I follow these tips:
1. I downloaded and installed Google Toolbar in my browser. It shows the page rank for my blogs. That kind of gives a rough idea if you are even "seen" by Google.
2. I registered my blogs with Technorati.com. There is a set of steps to do this, including adding some code to your blog template. They give detailed instructions on how to do this. Technorati clearly tells me who else in the blogging world links to my blog. It also shows authority and genuinity.
3. I registered my blogs with Google Analytics. They also have a set of steps and some code to add to your blog template. You can log into Google Analytics at any time and see data about the number of people visiting your site, which pages they are interested in, their geographical spread, the time they spent in an article and if the traffic came from direct hits, referring sites or search engines. It is an amazingly effective tool to gauge your effectiveness as a blogger.


Why Blog - The philosophy of blogging

Should you always blog in this day and age? We see people around us starting blogs all the time. They do it for different purposes. In my case I have some key motivations.
- I have been trying writing since I was 6 years. I have tried my hand at fiction, writing letters to the editor in local newspapers, tried participating in writing competitions. Basically I would rather be a writer and do it for a living. Before blogging I used to send emails to a bunch of people with my thoughts on different subjects even though my audience hated those emails. Thus, when I discovered blogging, I primarily thought of it as another tool for reaching a larger audience with my writing. Thus I did NOT start writing with blogs. I was always "blogging" in some form, even before the internet. If you have never been interested in writing, blogging may not help you. It will only make a person feel guilty about not maintaining a blog frequently.
- Even if you are not too interested in writing, blogging (for a professional) is a great way to build an online presence, and showcase your knowledge. It is one of the best resume formats. A frequently updated blog link makes people want to recruit a person. In my job searches, I send out cover letters with links to my blog articles - it is unusual, but credentializes you before you meet a person.
- Writer or not, a blog is a good way to atleast hone my marketing and presentation skills. You can experiment with a larger audience than you can imagine. Particularly for technical leaders and aspiring technologists, it is a good way to organize your thought process.
- One great reason to blog is its usefulness as a knowledge management tool. One of my earliest posts was about a few recipes for cooking. They were simple recipes, but they are available in the internet wherever I go. I refer to Praveen's blog about how to enable fiddler for Firefox all the time. I do not have to remember these details. You can blog about the little tips and tricks you learn in your professional and home life and then have them available to help you later.

Now, note that in all of these cases, there is a clear self-interest to blogging. There are people who have a different view - they claim that popularity of their blog is not their concern. They claim that the number of comments their blog attracts does not interest them. When someone mentioned such a near nirvana state in the Chennai blogcamp (2006) there were responses in agreement and disagreement. It is hard for me to adopt such an attitude about my blog. I shamelessly pimp my blogs to my friends and contacts. I want my views to be known - that is why I use analytics and technorati to measure my performance. I value feedback and discussion on what I am writing about.


Some tips for interested bloggers

1. What do you write about?
In my experience, when I think of some interesting angle, I brood over it for a day. Then I sit down and write a blog article for an hour. But I have noticed that I am constantly looking for such angles. I select some ideas, I reject others. Other bloggers have talked about a kind of urge (restlessness) you feel if you have not written a post for some time. All of this, of course, depends on time being available (more on that next). I write for my technical blog when I feel it is necessary to store some detail or process some knowledge.
Thus, in general,
- you can write opinion or commentary posts
- or you can write an informative, observation based post
Similarly,
- you can write long article sized posts (such as this one)
- or you can write shorter posts
Opinion or commentary posts attract people's attention. My Ilayaraja vs Rahman post still is one of my top picks. People will feel either for or against and they will comment on it. Of course, your opinion should be authentic, and have some fresh angle. Otherwise, you will not get repeat visitors and a regular readership.
But informative posts are also valuable - they will help you manage knowledge and build expertise. They will also provide more durable value to your readers.
I usually alternate between these. For example, this post you are reading is meant to be informative.
The core idea is to keep looking at any knowledge you acquire as a potential blog post.

2. When do you write?
I do not allocate any special time for writing and I do not stick to a schedule. Bloggers like Glenn Greenwald and Digby blog daily multiple times. But they also make money from blogging. Most of us amateurs cannot blog at that frequency.
The problem is to capture readership and make them come back for more. A frequency of once a month is insufficient for maintaining loyal readers.
There are many of us who start blogging ferociously and then just stop at a certain point. Then we feel guilty about stopping. There is no point in feeling guilty about not blogging - the readership is low, and most of the blogs do not attract traffic at all. It is hard to keep your spirits up under these circumstances. Also, as I said earlier, writing may not be your idea of fun. If so, there is no need to feel guilty.

3. How to attract initial readers?
I read an advice for frequent blogging, with one long article atleast a week and multiple shorter posts during the weekdays. Hard to do, but does attract loyalty (provided the content is good).
Send the blog article link to all your friends, family (when you feel ready about the content). There may be habitual forwarders among them and they will spread the news.
Have your freinds with popular blogs to link your blog.
If you have MSN or Yahoo Messenger, put the blog url in your signature. Put the url in your Facebook or Orkut or LinkedIn profile.
And have good content. There is no substitute for good content. Market yourself, but have good content.

4. Some Do's and Don'ts
Do NOT plagiarize - do not steal someone else's content and dump it in your blog. Do not quote an entire article and then add a link at the end. Write original content. Since you are publicizing your blog, having copied content will lead to people having a lower opinion of you.
Do NOT hope to make money out of blogging. Takes a very long time to be established and very hard to make money out of it.
When you finish writing a post, DO re-read it again for spelling mistakes and grammatical errors. They turn off visitors.
Whenever you quote someone's blog or opinion online, DO add a link to that quote. It is professional to do so.

Labels: