What is OpenSocial? “OpenSocial deﬁnes
Meet the Container A Container
Meet the Views Home Page
• Primary point of entry for members • Owner & Viewer are always the same • Content should be focused on the Member’s interaction with the application
Meet the Views Proﬁle Page
• Owner is the person who owns the proﬁle • Information displayed is seen by all who visit the proﬁle • Content should be focused on what the member does with the application
Meet the Views Canvas Page
• Serves many purposes & contexts for an application • Owner & Viewer might not be the same. Owner is determined by how it was navigated to. • Content can be anything related to the application
Dig the new Science! •
Technologies Involved • Accessible Social Data • Viral Features (Messaging, Network Updates) • Iterative Hello, World! Example
and Model logic) • JSON (for Social Data in gadget or using in OpenSocial REST APIs) • XML (for Gadget Spec, optional REST) • HTML (for your View layer) • REST (for interacting with your server or using OpenSocial REST APIs)
Social Data • Person •
friends (connections) • id • name ( givenName, familyName, unstructured ) • thumbnailUrl • aboutMe • currentLocation ( unstructured ) • jobs ( title, name, description, ﬁeld, startDate, endDate,) • schools ( name, startDate, endDate ) • urls • linkedin-ext ( require the feature in your gadget spec ) • numConnections • distance For more detail on ﬁelds available: http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.Person
Virality Connection Messaging requestSendMessage() /
Let’s Begin. • Start with
Hello, World! • Sprinkle some Social Data • Support some Views • Phone Home to your Server • Celebrate!
Adding Social Data 1. Setup
a new DataRequest object 2. Add a new fetchPerson request for Actors you need data for, fetchPeople requests for collections like friends, arrays of member ids... 3. Execute the request with request.send, specifying a callback that will act on the data
Functions to Know Get a
View Object var view = new gadgets.views.View(quot;viewName”); viewName in this case would be one of our supported views: canvas, proﬁle, home You need a view object to request navigation to it. Navigate Between Views gadgets.views.requestNavigateTo(view, optionalParameters) This initiates a transition from one view to another. • You can’t specify an Owner or Viewer in this context. It carries over from the last. • You use this function in an onClick event for a link • optionalParameters are JSON-format parameters to be passed only to a Canvas page. How to get these parameters on the next page will be detailed on the next slide
Functions to Know Receive URL
Parameters gadgets.views.getParams() Parameters sent via requestNavigateTo (or provided by other means of generating a canvas URL) are accessible through this function in JSON Hash format. Adjust View Height gadgets.window.adjustHeight() Adjusts the height of your gadget frame, while trying to auto-magically guess how much space you need, within the conﬁnes of the allowed height. Not always accurate. • You can specify an integer representing the exact pixel height to extend to.
How to Phone Home Use
gadgets.io.makeRequest() Inbound to your server, you’ll receive these parameters: opensocial_owner_id opensocial_viewer_id opensocial_app_id opensocial_app_url In addition, you’ll receive an OAuth signature for parameter validation. Implementation depends on your server-side language and is beyond the scope of this tutorial.
How to Phone Home Processing
the Callback • If your content type in the response is HTML, your response variable would be a string with that HTML. • If your content type in the response is JSON, it will automatically be destringiﬁed into a JSON object.