opensocial codelab

Post on 29-Jan-2018

1.388 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CHEWY TREWHELLADeveloper Advocate - Google

JOCHEN DELABIEWeb Developer - Netlog

OPENSOCIALCODELAB

PIETER DE SCHEPPERWeb Developer - Netlog

Getting Started

• Text Editor or Google Gadget Editor

• Web Hosting or built-in hosting from Google Gadget Editor

• You need a Netlog Account

• You can start developing in the Netlog Sandbox

Gadget Basics

Hello World example<?xml version="1.0" encoding="UTF-8" ?><Module> <ModulePrefs title="Hello World" author="Pieter De Schepper" author_email="pieter@netlog.com"> <Require feature="opensocial-0.8"/> </ModulePrefs> <Content type="html"> <![CDATA[ Hello World! ]]> </Content></Module>

Writing your first Social Gadget

function loadFriends(){ var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), 'viewer'); var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" }); var opt_params = {}; opt_params[opensocial.DataRequest.PeopleRequestFields.MAX] = 100; req.add(req.newFetchPeopleRequest(viewerFriends, opt_params), 'viewerFriends'); req.send(onLoadFriends);}

function init(){ loadFriends();} gadgets.util.registerOnLoadHandler(init);

Request Friends of viewer

Using App Data

function saveScore(score){ var req = opensocial.newDataRequest(); req.add(req.newUpdatePersonAppDataRequest("VIEWER", 'score', score)); req.send(onSaveScore);}

function onSaveScore(data){ if(!data.hadError()) { alert("Score saved!"); }}

Saving App Data

Sending notifications

function sendNotification(toUserID, fromName){ var recipients = [toUserID]; var msg = fromName + " has challenged you to a game of poker"; var params = {}; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.NOTIFICATION; var message = opensocial.newMessage(msg, params); opensocial.requestSendMessage(recipients, message);}

Sending notifications

Making use of views

<?xml version="1.0" encoding="UTF-8" ?><Module> <ModulePrefs title="Views" author="Pieter De Schepper" author_email="pieter@netlog.com"> <Require feature="opensocial-0.8"/> <Require feature="views"/> </ModulePrefs> <Content type="html" view="canvas"> <![CDATA[ Hello Canvas!<br/> <a href="#" onclick="gadgets.views.requestNavigateTo('profile')">To profile view</a> ]]> </Content> <Content type="html" view="profile"> <![CDATA[ Hello Profile!<br/> <a href="#" onclick="gadgets.views.requestNavigateTo('canvas')">To canvas view</a> ]]> </Content></Module>

Other features

• Content requests

• requestShareApp

• Dynamic height

• Netlog extensions

Usefull links

• Netlog OpenSocialhttp://en.netlog.com/go/developer/opensocial

• Netlog Sandboxhttp://en.netlog.com/go/developer/opensocial/sandbox

• OpenSocial referencehttp://code.google.com/apis/opensocial/docs/index.html

• Gadget referencehttp://code.google.com/apis/gadgets/devguide_landing.html

• OpenSocial Tutorialhttp://wiki.opensocial.org/index.php?title=OpenSocial_Tutorial

top related