16. Jaiku’s Jyri Engeström's 5 rules for social
networks: social objects
1. What is your object?
2. What are your verbs?
3. How can people share the objects?
4. What is the gift in the invitation?
5. Are you charging the publishers or the spectators?
http://tinyurl.com/yus8gw
17. How do we socialize objects
online
without having to create yet
another social network?
19. The Trouble with Developing Social Apps
Which site do I build my app for?
20. Let’s work on that…
Using OpenSocial, I can build apps for all
of these sites!
21. What’s offered by OpenSocial?
• Activities
o What are people up to on the web
• People/Profile Info
o Who do I know, etc.
• Persistent datastore
o Handles key/value pairs
26. What’s in OpenSocial?
• JavaScript API - Now
• REST Protocol - New
• Templates - Prototype in Shindig
27. OpenSocial’s JavaScript API
• OpenSocial JS API
• Gadget JS API
• Gadget XML schema
• OpenSocial v0.7 is live
• OpenSocial v0.8 is being deployed now
• Specs and release notes: http://opensocial.org
28. OpenSocial’s REST Protocol
• Access social data without JavaScript
• Works on 3rd party websites / phones / etc
• Uses OAuth to allow secure access
• Open source client libraries in development
o Java, PHP, Python, <your fav language here>
• Being deployed with OpenSocial v0.8
• Spec’s available at http://opensocial.org
29. OpenSocial Templates
• Writing JavaScript is hard
• Writing templates is easy
• Templates also give
o Consistent UI across containers
o Easy way to localize
o More interesting content options when inlining
into container (activities, profile views)
o Ability to serve millions of dynamic pages per
day without a server
30. Design principles
Create a template language that is:
• Simple
o Easy markup for creating UI and binding data
• Fast
o Supports server-side optimizations
• Extensible
o Standard reusable controls (buttons, lists, links, etc.)
• Everywhere
o Only need to include a single JavaScript file
31. Concepts:
• Markup
o A set of standard tags and behaviors that provide
developers with a simple, declarative language for
assembling apps.
• Templating
o A set of standard elements implemented by containers.
o A method for taking structured data and rendering UI
elements in an arbitrary markup.
• Data Pipelining
o A method for grabbing OpenSocial and third-party data
declaratively (or in script) and joining it to templates.
36. Template Status
• High-level specification complete:
o http://wiki.opensocial-templates.org
• Prototype implementation available:
o http://ostemplates-demo.appspot.com
• GET INVOLVED! Tag feedback/suggestions appreciated:
o http://tech.groups.yahoo.com/group/os-templates/
• Code for templates is in Shindig: patches welcome:-)
37. OpenSocial is what you make it.
• OpenSocial is an open source project.
• The spec is controlled by the community.
• Anyone can contribute and have a voice.
• http://groups.google.com/group/opensocial/
o “OpenSocial and Gadgets spec” subgroup
• OpenSocial Foundation
o Get involved to nominate and elect board reps
o http://www.opensocial.org/opensocial-foundation/
38. A note on compliance
• OpenSocial is designed for many sites
• Building an app:
o Technology
o Policy
• OpenSocial Compliance Tests
o http://code.google.com/p/opensocial-
resources/wiki/ComplianceTests
44. Owner and Viewer Relationship
Applications
has views
Owner Viewer
has has
Friends Friends
45. Understanding the Gadget XML
ModulePrefs define
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?> characteristics of the
<Module> gadget, such as title,
author, etc.
<ModulePrefs title=quot;Hello World!quot;>
Module node <Require feature=quot;opensocial-0.7quot; />
defines the gadget.
</ModulePrefs>
<Content type=quot;htmlquot;> Require nodes should
be added for all
<![CDATA[ desired features
<script>
function init(){
alert(quot;hello worldquot;);
}
gadgets.util.registerOnLoadHandler(init);
Define your gadget
</script>
html within Content
node ]]>
</Content>
</Module>
46. Retrieve Friend Information
function getFriendData() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest(VIEWER), 'viewer');
req.add(req.newFetchPeopleRequest(VIEWER_FRIENDS),
'viewerFriends'); Place an Create a new data
req.send(onLoadFriends); asynchronous call to
the container.
request object and
add the desired sub-
} requests.
function onLoadFriends(response) {
var viewer = response.get('viewer').getData();
var viewerFriends = response.get('viewerFriends').getData();
///More code
} Handle the returned
data in callback
47. Persisting Data
function populateMyAppData() {
Use a
var req = opensocial.newDataRequest(); newUpdatePersonAppDa
var data1 = Math.random() * 5; taRequest() to update
data.
var data2 = Math.random() * 100;
req.add(req.newUpdatePersonAppDataRequest(
quot;VIEWERquot;,quot;AppField1quot;, data1));
req.add(req.newUpdatePersonAppDataRequest(
quot;VIEWERquot;,quot;AppField2quot;, data2));
req.send(requestMyData);
}
48. Fetching persisted data
function requestMyData() { Use a
var req = opensocial.newDataRequest(); newFetchPersonAppD
var fields = [quot;AppField1quot;, quot;AppField2quot;]; ataRequest() to fetch
data.
req.add(req.newFetchPersonRequest(
opensocial.DataRequest.PersonId.VIEWER),quot;viewerquot;);
req.add(req.newFetchPersonAppDataRequest(quot;VIEWERquot;,
fields), quot;viewer_dataquot;);
req.send(handleReturnedData);
AppData is returned as a
} 2-level Map, with person
id as the first key and
function handleReturnedData(data) { propertyname as the
next key
var mydata = data.get(quot;viewer_dataquot;);
var viewer = data.get(quot;viewerquot;);
me = viewer.getData();
var appField1 = mydata[me.getId()][quot;AppField1quot;];
///More code
}
49. Posting an Activity
function postActivity(text) {
var params = {}; requestCreateActivity is
a request, a specific
params[opensocial.Activity.Field.TITLE] = text; may choose to
container
var activity = opensocial.newActivity(params); ignore it.
opensocial.requestCreateActivity(activity,
opensocial.CreateActivityPriority.HIGH,
callback);
}
postActivity(quot;This is a sample activity, created
at quot; + new Date().toString())
50. How to build an OpenSocial application
Best Practices
51. Best practices : Check for errors
• Both the request and sub-requests can have
errors, use hadError() to check.
function response(data) {
if (!data.hadError()) {
...
} else {
if (data.get(quot;reqquot;).hadError()) {
alert(data.get(quot;reqquot;).getErrorMessage());
}
} else {
alert('Unknown error occurred');
};
52. Best practices : Be specific
• Specify which fields you want to use:
only ID, NAME and THUMBNAIL_URL are returned
by default
function request() {
var req = opensocial.newDataRequest();
var params = {};
params[opensocial.DataRequest.PeopleRequestFields
.PROFILE_DETAILS] = [
opensocial.Person.Field.PROFILE_URL
];
req.add(req.newFetchPersonRequest(
opensocial.DataRequest.PersonId.VIEWER, params),
quot;reqquot;);
req.send(response);
};
53. Best practices : Capability Discovery
• Check for supported features and fields
var supportsAboutMe =
opensocial.getEnvironment().supportsField(
opensocial.Environment.ObjectType.PERSON,
opensocial.Person.Field.ABOUT_ME
);
if (gadgets.util.hasFeature('hi5')) {
mediaItem.setField(
hi5.ActivityMediaItemField.LINK,
quot;http://linkurlquot;);
}
54. Best Practises : Use the container's cache
Use the container's content cache
function showImage() {
imgUrl = 'http://foo.com/bar.png';
cachedUrl = gadgets.io.getProxyUrl(imgUrl);
html = ['<img src=quot;', cachedUrl, 'quot;>'];
document.getElementById('dom_handle').innerHTML =
html.join('');
};
showImage();
• Also check out
o Content-Rewriter feature
o Preloading
o Using App Data as content cache
55. Best practises : Web development 101
• Control the caching of your content, http headers:
o Cache-Control
o Last-Modified
o Expires
o E-Tag
• Reduce number of http requests
o Combine JS and CSS files into one file
o Combine images into single sprite + CSS positioning
• Use Google's AJAX libraries API
o <script src=quot;http://ajax.googleapis.com/.../prototype.js
• Other techniques:
o GZip content
o Minify JS and CSS
o See YSlow!
56. Hosting your application
• Host it anywhere you want to, with any back-end
• Keep in mind:
o Popular apps like iLike get > 200k req / minute peak
o Means dealing with lots of scalability issues!
o DB Sharding, memcache pools, server farms..
• Why not use a cloud service like:
o Google App Engine
o Joyent.com
o Amazon EC2
59. OpenSocial Monetization
• Ads from Ad Networks
o AdSense, RightMedia
o BuddyPoke, Rate My Friend
• Brand/Private Label App
o Sony Ericsson MTV Roadies app on orkut
• Sell virtual or real goods
• Free -> Freemium
• Referrals
• Virtual currency
60. Success Story: Buddy Poke
• #1 OpenSocial app on orkut
• 8M installs for orkut, hi5, MySpace
• $1-2 CPM
• #1 App for App Engine w/ millions daily PV
61. Success Story: PhotoBuzz
• 6M+ installs on hi5 and orkut
• CPM $1-3, especially good on orkut
• 4M buzzes per day
• Small team of 4 people, profitable
63. Container Specific Extensions
MySpace
• photo albums
• videos
hi5
• status
• presence
• photo albums
Netlog
• credits api extension
• translation tool for free
Imeem
• music metadata api
65. Becoming an OpenSocial Container
• Question:
o How do you become an OpenSocial container?
• Answer:
o The Apache incubator project “Shindig” serves this
purpose!
66. What is Shindig ?
• Open source reference implementation of OpenSocial &
Gadgets specification
• An Apache Software Incubator project
• Available in Java & PHP
• http://incubator.apache.org/shindig
It’s Goal:
“Shindig's goal is to allow new sites to start hosting social apps
in under an hour's worth of workquot;
67. Introduction to Shindig Architecture
• Gadget Server
• Social Data Server
• Gadget Container JavaScript
70. Social Server - RESTful API
• Preview available on
o iGoogle
o Orkut
o Hi5
• New development models
o Server to server & Mobile!
• Try it out:
curl http://localhost:8080/social/rest/people/john.doe/@all
74. Implementing Shindig - Data sources
• Integrate with your own data sources
o People Service
o Activities Service
o App Data Service
class MyPeopleService implements PeopleService {
...
}
class MyAppDataService implements AppDataService {
...
}
class MyActivitiesService implements ActivitiesService {
...
}
76. Implementing Shindig - Java
Code at http://chrisschalk.com/shindig_docs/io/shindig-io.html
import org.apache.shindig.social.opensocial.ActivitiesService;
public class SQLActivitiesService implements ActivitiesService {
private SQLDataLayer sqlLayer;
@Inject
public SQLActivitiesService(SQLDataLayer sqlLayer) {
this.sqlLayer = sqlLayer;
}
77. Implementing Shindig - Java
public ResponseItem<List<Activity>> getActivities(List<String> ids,
SecurityToken token) {
Map<String, List<Activity>> allActivities = sqlLayer.getActivities();
List<Activity> activities = new ArrayList<Activity>();
for (String id : ids) {
List<Activity> personActivities = allActivities.get(id);
if (personActivities != null) {
activities.addAll(personActivities);
}
}
return new ResponseItem<List<Activity>>(activities);
}
78. Implementing - Make it a platform
• Add UI Elements
o App Gallery
o App Canvas
o App Invites
o Notification Browser
• Developer Resources
o Developer Console
o Application Gallery
• Scale it Out!
79. Implementing - Scale it Out!
• Prevent Concurrency issues
• Reduce Latency
• Add Caching
• Add more caching!
80. Usage Example: Sample Container
• Static html sample container
• No effort to get up and running
• No database or features
81. Usage Example: Partuza
• Partuza is a Example social network site, written in PHP
• Allows for local gadget development & testing too
• Use as inspiration (or copy) for creating your own social site
• http://code.google.com/p/partuza
82. OpenSocial for intranet, portals
Sun Microsystems
• Socialsite: Shindig + gadget based UI written in Java
• Open Source https://socialsite.dev.java.net/
Upcoming from Impetus
• Zest: Shindig + Drupal (PHP)
• Zeal: Shindig + Liferay (Java)
84. Summary
• Become an OpenSocial Container
o Get Shindig (PHP or Java)
o Look at examples & documentation
o Implement Services
o Add UI
o Scale it out
• Resources & Links:
o http://www.chabotc.com/gdd/
85. What is Friend Connect?
Allows any site to become an OpenSocial container by simply
copying a few snippets of code into your site
http://www.google.com/friendconnect/
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96. Friend Connect gives ...
• Users
o ... more ways to do more things with my friends
• Site owners
o ... more (and more engaged) traffic for my site
• App developers
o ... more reach for my apps
and ... make it easy
97. OpenSocial Gadget Contest for Southeast Asia
• To support the developer community and encourage innovation on the
OpenSocial platform in Southeast Asia
• Countries: Malaysia, Philippines, Singapore, Thailand, Vietnam
• 4 winners per country: Nintendo Wii, Apple iPod Touch prizes
• Judging panel: Google, eXo Platform, Friendster, Globant, hi5
• Dates:
o Registration opens: Nov 15, 2008
o Registration ends: Jan 10, 2009
o Winners notified: Jan 23, 2009
o Results announced: Feb 6, 2009
• The REAL reward for local developers: winning gadgets to be promoted on
OpenSocial partner websites to potentially reach hundreds of millions of Internet
users worldwide
• http://code.google.com/events/apacdevfest/contest