opensocial codelab

14
CHEWY TREWHELLA Developer Advocate - Google JOCHEN DELABIE Web Developer - Netlog OPENSOCIAL CODELAB PIETER DE SCHEPPER Web Developer - Netlog

Upload: pieter-de-schepper

Post on 29-Jan-2018

1.388 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Opensocial Codelab

CHEWY TREWHELLADeveloper Advocate - Google

JOCHEN DELABIEWeb Developer - Netlog

OPENSOCIALCODELAB

PIETER DE SCHEPPERWeb Developer - Netlog

Page 2: Opensocial Codelab

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

Page 4: Opensocial Codelab

Gadget Basics

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

Page 6: Opensocial Codelab

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

Page 8: Opensocial Codelab

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

Page 11: Opensocial Codelab

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

Page 13: Opensocial Codelab

Other features

• Content requests

• requestShareApp

• Dynamic height

• Netlog extensions

Page 14: Opensocial Codelab

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