OpenSocial Intro

  • 2,462 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,462
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
40
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. OpenSocial
  • 2. OpenSocial’s goal:
    • Make the web more social
  • 3. The social internet
    • A social website..
    • Provides a feature that becomes more engaging as the number of users grows.
    • Uses relationships between people to present users interesting information.
  • 4. The social internet Some social websites...
  • 5. The social internet
    • A social website..
    • Has overhead to manage users and relationships.
    • Grows slowly because users must sign up to use the site.
    • What if we remove
    • the overhead?
    • Developers can focus on providing features, not managing users.
  • 6. The social internet
    • A social network..
    • Manages large numbers of users and relationships.
    • Is slow to add new features.
  • 7. The social internet Many social networks...
  • 8. The social internet
    • How do we add new features to social networks?
    • Make the social network a platform.
    • Give creative developers the tools to add the features themselves.
  • 9. The social internet
    • A social application...
    • Lets the social network manage users and relationships.
    • Adds new features to the social network.
    • Lets users “install” the application without signing up for new accounts.
    • Grows quickly because users are already communicating with each other.
  • 10. The social internet Lots of social apps...
  • 11. Need for a social API
    • How do we put apps in social networks?
  • 12. A day in the life of a social app developer
  • 13. A day in the life of a social app developer
  • 14. Introduction to OpenSocial
    • Numbers:
    • 19+ implemented Containers
    • 40+ committed Containers
    • 3000+ applications
    • 400,000,000+ of users
    In China:
  • 15. The OpenSocial APIs
    • Client-side:
    • Gadgets XML
    • Gadgets JavaScript
    • OpenSocial JavaScript
    • Server-side:
    • RESTful protocol
    • RPC protocol
    • Versions:
    • 0.6 - Client-side APIs introduced
    • 0.7 - Server-side APIs introduced
    • 0.81 (current) - Server-side APIs finalized
  • 16. Gadgets
    • Not widgets, not sprockets, not gidgets, not wadgets
  • 17. Gadgets
    • A gadget spec:
    • Is an XML file.
    • Defines metadata about an OpenSocial app.
    • Is highly cacheable and does not need a high performance server.
    • Gadgets use existing web standards
    • XML to define metadata.
    • HTML for markup.
    • JavaScript for interactivity.
    • CSS for presentation.
  • 18. Gadgets
    • A gadget server:
    • Takes the gadget spec as input.
    • Performs optimizations on the gadget spec.
    • Outputs HTML , JavaScript , and CSS as one document.
  • 19. Gadgets
    • A container:
    • Displays the social network’s user interface.
    • Opens an IFrame to the rendered gadget.
    Containers and gadget servers are both run by the social network, but do not need to be on the same machine, or even domain.
  • 20. Gadgets
    • Example gadget XML spec:
    • Uses HTML to print “Hello World”.
    • Colors the text red with CSS .
    • Alerts annoying message with JavaScript .
    <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <Module> <ModulePrefs title=&quot;Hello World!&quot;> <Require feature=&quot;dynamic-height&quot; /> </ModulePrefs> <Content type=&quot;html&quot;><![CDATA[ <h1>Hello World</h1> <style type=&quot;text/css&quot;> h1 { color: #dd0000; } </style> <script type=&quot;text/javascript“> alert(“Hello More!”); </script> ]]> </Content></Module> Live Demo
  • 21. Gadgets
    • JavaScript utility functions for gadgets:
    • gadgets.io.makeRequest() Make cross-domain AJAX calls to remote servers.
    • gadgets.json.parse() and gadgets.json.stringify() Native JSON support.
    • gadgets.util.escapeString() Make text safe for display via innerHTML.
    • gadgets.util.registerOnLoadHandler() Execute code when the page is finished loading.
  • 22. Gadgets
    • A gadget can require additional JS libraries (“features”).
    • minimessage – Display short messages to the user .
    • tabs – Create a tabbed user interface
    • dynamic-height - Change the size of your gadget in the container.
    • views - Navigate between different surfaces of the container.
    • skins - Make your gadget change its styles to match the container.
    • Containers may offer custom features...
    <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <Module> <ModulePrefs title=&quot;Hello World!&quot;> <Require feature=&quot;dynamic-height&quot; /> </ModulePrefs> <Content type=&quot;html&quot;> <![CDATA[ ... ]]> </Content> </Module> Live Demo
  • 23. Gadgets
    • What are views?
    • Gadgets can render in different locations on a container.
    • Rendering area changes from small to large.
    • Certain pages might be public, some are private.
    • Containers may have different policies depending on the page, especially when the gadget displays ads.
    • Views provide a way for gadgets to provide different functionality depending on where it is rendered.
  • 24. Gadgets
    • iGoogle &quot;home&quot; view:
    • On iGoogle, the &quot;home&quot; view is a small, private page that does not allow ads.
  • 25. Gadgets
    • iGoogle &quot;canvas&quot; view:
    • Large private view, allows ads.
  • 26. Gadgets
    • Working with views in the gadget XML:
    • <Content> sections are repeated for each view .
    • Add a view=&quot;view name&quot; attribute to each section.
    • Content sections may support multiple views, for example view=&quot;home,canvas&quot;
    <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> <Module> <ModulePrefs title=&quot;Hello World!&quot;> <Require feature=“views&quot; /> </ModulePrefs> <Content type=&quot;html&quot; view=&quot;home&quot; > <![CDATA[ ... ]]> </Content> <Content type=&quot;html&quot; view=&quot;canvas&quot; > <![CDATA[ ... ]]> </Content> </Module> Live Demo
  • 27. Gadgets <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?><Module> <ModulePrefs title=&quot;Hello Social!&quot;> <Require feature=&quot;opensocial-0.8&quot; /> </ModulePrefs> <Content type=&quot;html&quot;> <![CDATA[ ... ]]> </Content> </Module> The OpenSocial JavaScript API is a gadget feature, too! Live Demo
  • 28. The OpenSocial JavaScript API
  • 29. Making Gadgets Social
    • Gadgets can become social with OpenSocial JavaScript API
    • OpenSocial API has three core services:
    • People & Friends
    • Access profile information
    • Access friends information
    • Activities
    • See what you’re friends are up to
    • Share what you are doing
    • Persistence
    • Provide state without a server
    • Share data with your friends
  • 30. The OpenSocial JavaScript API
    • Representing users:
    • Client-side, users must work with the VIEWER and the OWNER .
  • 31. The OpenSocial JavaScript API
    • Multiple personalities:
    • When you visit your own profile, you are both the VIEWER and the OWNER .
  • 32. The OpenSocial JavaScript API
    • OpenSocial requests:
    • An OpenSocial DataRequest is created.
    • Requests are added to the DataRequest.
    • The DataRequest is sent to the server asynchronously.
    • When the request finishes, the supplied callback will be called.
    function request() { var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest(&quot;OWNER&quot;), &quot;get_owner&quot;); req.add(req.newFetchPersonRequest(&quot;VIEWER&quot;), &quot;get_viewer&quot;); req.add(req.newFetchActivitiesRequest(&quot;VIEWER&quot;), &quot;vactivities&quot;); req.add(req.newFetchPersonAppDataRequest(&quot;OWNER&quot;, &quot;*&quot;), &quot;odata&quot;); ... req.send ( response );}; function response (data) { ... }; gadgets.util.registerOnLoadHandler(request);
  • 33. The OpenSocial JavaScript API
    • OpenSocial responses:
    • Responses are bundled according to the keys specified in the request.
    • Check for an error at the global response level .
    • Check for an error at the specific response level .
    • Use getData() to retrieve the actual information in a request.
    function response(data) { if ( data.hadError() ) { if ( data.get(&quot;get_owner&quot;).hadError() ) { ... } if ( data.get(&quot;get_viewer&quot;).hadError() ) { ... } ... } var owner = data.get ( &quot;get_owner&quot;). getData (); var viewer = data.get( &quot;get_viewer&quot;). getData (); };
  • 34. The OpenSocial JavaScript API Working with people:
    • opensocial.Person - JavaScript representation of a user.
  • 35. The OpenSocial JavaScript API Request one person: req.add(req.newFetchPersonRequest( idspec , opt_params ), &quot;key&quot;);
    • idspec can be either “VIEWER”, “OWNER” or an ID number.
    • opt_params contains extra request parameters, such as which profile fields to fetch.
    newFetchPersonRequest responses: var owner = data.get(&quot;key&quot;).getData(); alert(owner.getDisplayName());
    • Data contains a single opensocial.Person object.
    • Person objects can contain lots of information, such as addresses, companies, phone numbers, favorite movies, and thumbnail urls.
  • 36. The OpenSocial JavaScript API Methods available on an OpenSocial Person:
    • getDisplayName() Gets a text display name for this person; guaranteed to return a useful string.
    • getField(key, opt_params) Gets data for this person that is associated with the specified key.
    • getId() Gets an ID is permanently associated with this person.
    • isOwner() Returns true if this person object represents the owner of the current page.
    • isViewer() Returns true if this person object represents the currently logged in user.
    Live Demo
  • 37. The OpenSocial JavaScript API
    • ABOUT_ME
    • ACTIVITIES
    • ADDRESSES
    • AGE
    • BODY_TYPE
    • BOOKS
    • CARS
    • CHILDREN
    • CURRENT_LOCATION
    • DATE_OF_BIRTH
    • DRINKER
    • EMAILS
    • ETHNICITY
    • FASHION
    • FOOD
    • GENDER
    • HAPPIEST_WHEN
    • HAS_APP
    • HEROES
    • HUMOR
    • ID
    • INTERESTS
    • JOB_INTERESTS
    • JOBS
    • LANGUAGES_SPOKEN
    • LIVING_ARRANGEMENT
    • LOOKING_FOR
    • MOVIES
    • MUSIC
    • NAME
    • NETWORK_PRESENCE
    • NICKNAME
    • PETS
    • PHONE_NUMBERS
    • POLITICAL_VIEWS
    • PROFILE_SONG
    • PROFILE_URL
    • PROFILE_VIDEO
    • QUOTES
    • RELATIONSHIP_STATUS
    • RELIGION
    • ROMANCE
    • SCARED_OF
    • SCHOOLS
    An OpenSocial Person's fields:
    • SEXUAL_ORIENTATION
    • SMOKER
    • SPORTSSTATUSTAGS
    • THUMBNAIL_URL
    • TIME_ZONE
    • TURN_OFFS
    • TURN_ONS
    • TV_SHOWS
    • URLS
  • 38. The OpenSocial JavaScript API Working with people:
    • A Collection represents many opensocial.Person objects.
  • 39. The OpenSocial JavaScript API Request many people: var idspec = opensocial.newIdSpec({ “ userId” : “OWNER”, “groupId” : “FRIENDS”}); req.add(req.newFetchPeopleRequest( idspec , opt_params ), &quot;key&quot;);
    • idspec is an object that can represent groups of people. “userId” can be “VIEWER” or “OWNER” or an ID, and “groupId” can be “SELF”, “FRIENDS”, or the name of a group.
    • opt_params contains extra request parameters, such as which profile fields to fetch, and how to order or filter the returned people.
    Process the response: var owner_friends = data.get(&quot;key&quot;).getData(); owner_friends.each(function (person) { alert(person.getDisplayName()); });
    • Data contains a Collection of opensocial.Person objects.
    Live Demo
  • 40. The OpenSocial JavaScript API Working with data:
    • Persistent data gives apps key, value storage directly on the container.
    • String only, but conversion to JSON allows for storage of complex objects.
    • Storage per app per user - scales well with growth.
    • Ideal for settings, customizations.
  • 41. The OpenSocial JavaScript API Set persistent data: req.add(req.newUpdatePersonAppDataRequest( idspec , key , value ));
    • idspec can only be “VIEWER”.
    • key is the name under which this data will be stored.
    • value is a string representing the data to store.
  • 42. The OpenSocial JavaScript API Fetch persistent data: var idspec = opensocial.newIdSpec({ &quot;userId&quot; : &quot;OWNER&quot;, &quot;groupId&quot; : &quot;SELF&quot; }); req.add(req.newFetchPersonAppDataRequest( idspec , keys ), &quot;key&quot;); req.add(req.newFetchPersonRequest(&quot;OWNER&quot;), &quot;ownerkey&quot;);
    • idspec is an object that can represent groups of people, the same as newFetchPeopleRequest.
    • keys is a list of persistent data keys to retrieve the data for.
    • The owner is requested because the data returned is indexed by user ID and we want the owner’s data.
    newFetchPersonAppDataRequest responses: var app_data = data.get(&quot;key&quot;).getData(); var value = app_data[owner.getId()][key];
  • 43. The OpenSocial JavaScript API Fetch persistent data: { &quot;1234567890&quot; : { &quot;key1&quot; : &quot;value1&quot; }, &quot;2345678901&quot; : { &quot;key1&quot; : &quot;value2&quot; } }
    • Data is returned as an object indexed by ID number, then as an object indexed by key name, even if there is only data returned for one user!
    { &quot;1234567890&quot; : { &quot;key1&quot; : &quot;value1&quot; } }
    • Multiple people:
    { &quot;1234567890&quot; : { &quot;key1&quot; : &quot;value1&quot;, &quot;key2&quot; : &quot;value2&quot; } }
    • One person, multiple keys:
    Live Demo
  • 44. The OpenSocial JavaScript API Working with activities:
    • API to post information about what users are doing with your app.
    • Many containers have support for images and some HTML.
    • Channel to grow your application.
    orkut MySpace hi5
  • 45. The OpenSocial JavaScript API Post an activity: function postActivity( text ) {    var params = {};    params[opensocial.Activity.Field.TITLE] = text ;    var activity = opensocial.newActivity (params);    opensocial.requestCreateActivity (activity,      opensocial.CreateActivityPriority.HIGH, callback); };
    • Assign the activity text to the TITLE field.
    • Call opensocial.newActivity() to create a new Activity instance.
    • Call opensocial.requestCreateActivity() to post the activity to the container.
    Live Demo
  • 46. RESTful and RPC protocols
    • Servers talking to servers
  • 47. RESTful and RPC protocols
    • Opens new development models
    • Background processing.
    • Easier Flash integration.
    • Mobile applications.
  • 48. RESTful and RPC protocols
    • Communication methods:
    • RESTful (Representational State Transfer)
    • RPC (Remote Procedure Call)
    • Formats:
    • XML
    • JSON
    • AtomPub
  • 49. RESTful and RPC protocols
    • REST:
    • Resources are URLs.
    /people/{guid}/@all
    • All people connected to the given user:
    Example - People: /people/{guid}/@friends
    • All friends of the given user:
    /people/{guid}/@self
    • Profile of the given user:
    /people/@me/@self
    • Profile of the authenticated user:
    /people/@supportedFields
    • Supported Person fields:
  • 50. RESTful and RPC protocols
    • Response format (JSON, XML, AtomPub)
    • Request extra fields
    • Filtering:
    • Paging:
    fields={-join|,|field}. filterBy={fieldname} filterOp={operation}filterValue={value} updatedSince={xsdDateTime} networkDistance={networkDistance} count={count} sortBy={fieldname} sortOrder={order} startIndex={startIndex} format={format} Querystring parameters customize requests:
  • 51. RESTful and RPC protocols <person xmlns=&quot; http://ns.opensocial.org/2008/opensocial &quot;> <id></id> <displayName></displayName> <name> <unstructured>Jane Doe</unstructured></name> <gender>female</gender> </person> REST responses (Person): {&quot;id&quot; : &quot;example.org:34KJDCSKJN2HHF0DW20394&quot;, &quot;displayName&quot; : &quot;Janey&quot;, &quot;name&quot; : {&quot;unstructured&quot; : &quot;Jane Doe&quot;}, &quot;gender&quot; : &quot;female&quot;} JSON: XML:
  • 52. RESTful and RPC protocols REST responses (Person): AtomPub: <entry xmlns=&quot; http://www.w3.org/2005/Atom &quot;> <content type=&quot;application/xml&quot;> <person xmlns=&quot; http://ns.opensocial.org/20 08/opensocial &quot;> <name> <unst ructured>Jane Doe</unstructured> </name> <gender>female</gender></person> </content> <title/> <updated>2003-12-13T18:30:02Z</updated> <author/> <id>urn:guid:example.org:34KJDCSKJN2HHF0DW20394</id> </entry>
  • 53. RESTful and RPC protocols
    • REST:
    • Perform operations using different HTTP methods on each URL.
    • CRUD:
    • C reate
    • R etrieve
    • U pdate
    • D elete
    • HTTP:
    • POST
    • GET
    • PUT
    • DELETE
  • 54. RESTful and RPC protocols
    • REST has some disadvantages:
    • Batch support requires multiple HTTP requests, or a contrived URL scheme.
    • Specifying multiple users via querystring is difficult. Is ?uid=1234,5678 the same resource as ?uid=5678,1234 ?
  • 55. RESTful and RPC protocols
    • RPC:
    • One endpoint - parameters specify methods to call.
    • Batch support.
    • Specify collections of users through passed arguments, not URLs.
    POST /rpc HTTP/1.1 Host: api.example.org Authorization: <Auth token> Content-Type: application/json { &quot;method&quot; : &quot;people.get&quot;, &quot;id&quot; : &quot;myself&quot; &quot;params&quot; : { &quot;userid&quot; : &quot;@me&quot;, &quot;groupid&quot; : &quot;@self&quot; }} Example - Fetch current user:
    • Request
    HTTP/1.x 207 Multi-Status Content-Type: application/json { &quot;id&quot; : &quot;myself&quot; &quot;result&quot; : { &quot;id&quot; : &quot;example.org:34KJDCSKJN2HHF0DW20394&quot;, &quot;name&quot; : { &quot;unstructured&quot; : &quot;Jane Doe&quot;}, &quot;gender&quot; : &quot;female&quot; }}
    • Response
  • 56. RESTful and RPC protocols Authentication: Both protocols use OAuth to identify users and apps. Depending on what the application needs to do, it can use two-legged or three-legged OAuth.
    • Two-legged OAuth:
    • The application authenticates directly with the container .
    • Perform non-user specific operations:
      • Update persistent data for app users.
      • Can request information for users who have shared their profile information with the app.
    • Three-legged OAuth:
    • The user tells the container to give profile access to the application .
    • Perform user specific operations:
      • Post activities.
      • Fetch friends of the current user.
  • 57. RESTful and RPC protocols
    • Client libraries are being created for PHP, Java, Python, Ruby.
    • Help you connect to OpenSocial containers, and work with social data on your server.
    Sample: Login, get thumbnail and friends. OpenSocialClient c = new OpenSocialClient(&quot;myspace.com&quot;); c.setProperty(OpenSocialClient.Properties.REST_BASE_URI, &quot;http://api.myspace.com/v2/&quot;); c.setProperty(OpenSocialClient.Properties.CONSUMER_SECRET, <MYSPACE_SECRET>); c.setProperty(OpenSocialClient.Properties.CONSUMER_KEY, <MYSPACE_APP_KEY>); c.setProperty(OpenSocialClient.Properties.VIEWER_ID, <YOUR_MYSPACE_ID>); OpenSocialPerson p = c.fetchPerson(<YOUR_MYSPACE_ID>); OpenSocialField f = p.getField(&quot;thumbnailUrl&quot;); System.out.println(f.getStringValue()); Collection<OpenSocialPerson> friends = c.fetchFriends(<YOUR_MYSPACE_ID>); for (OpenSocialPerson friend : friends) { System.out.println(friend.getDisplayName()); }