Hi Parag, Where are you trying to run this app? Make sure that you're in any developer sandboxes you need to be in to run development apps, and that you have a properly configured friends list.
Providing more information about the response you're seeing would help as well. ~Arne On Jul 23, 11:50 pm, Parag Shukla <parag.shukla....@gmail.com> wrote: > Hi I am new to this gadget development and i am trying to run gift > example given by google, but i am not getting friends list in the > application, the code is given below. > > gift.xml: > <?xml version="1.0" encoding="UTF-8" ?> > <Module> > <ModulePrefs title="DSK51.2" > author="Parag" > author_email="pinku...@gmail.com" > height="280" > width="280" > description="__MSG_description__" > thumbnail="Sunset.jpg"> > > <Require feature="opensocial-0.8" /> > </ModulePrefs> > <Content type="html"> > <![CDATA[ > <script src="friends.js"></script> > <script src="gift.js"></script> > <script language="javascript"> > function init() > { > loadFriends(); > makeOptionsMenu(); > } > > gadgets.util.registerOnLoadHandler(init); > </script> > <div id='main'> > <div id='give'> > <form id='gift_form'> > Give <span > id='gifts'></span> to <span id='friends'></span>. > <a > href='javascript:void(0);' onclick='giveGift();'>Give!</ > a> > </form> > </div> > <div id='given'></div> > </div> > ]]> > </Content> > </Module> > > gift.js: > var givenGifts = {}; > var globalGiftList = ['a cashew nut', 'a peanut', 'a hazelnut', 'a red > pistachio nut']; > > function updateGiftList(viewer, data, friends) { > var json = null; > if (data[viewer.getId()]) { > json = data[viewer.getId()]['gifts']; > } > > if (!json) { > givenGifts = {}; > } > try { > givenGifts = gadgets.json.parse(gadgets.util.unescapeString(json)); > } catch (e) { > givenGifts = {}; > } > > var html = new Array(); > html.push('You have given:'); > html.push('<ul>'); > for (i in givenGifts) { > if (i.hasOwnProperty) { > html.push('<li>', friends.getById(i).getDisplayName(), ' received > ', globalGiftList[givenGifts[i]], '</li>'); > } > } > html.push('</ul>'); > document.getElementById('given').innerHTML = html.join(''); > > } > > function giveGift() { > var nut = document.getElementById('nut').value; > var friend = document.getElementById('person').value; > > givenGifts[friend] = nut; > var json = gadgets.json.stringify(givenGifts); > > var req = opensocial.newDataRequest(); > req.add(req.newUpdatePersonAppDataRequest("VIEWER", 'gifts', json)); > req.add(req.newFetchPersonRequest("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'); > > var viewer = opensocial.newIdSpec({ "userId" : "VIEWER" }); > req.add(req.newFetchPersonAppDataRequest(viewer, 'gifts'), 'data'); > req.send(onLoadFriends); > > } > > function makeOptionsMenu() { > var html = new Array(); > html.push('<select id="nut">'); > for (var i = 0; i < globalGiftList.length; i++) { > html.push('<option value="', i, '">', globalGiftList[i], '</ > option>'); > } > html.push('</select>'); > document.getElementById('gifts').innerHTML = html.join(''); > > } > > friends.js: > function loadFriends() { > var req = opensocial.newDataRequest(); > req.add(req.newFetchPersonRequest("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'); > > var viewer = opensocial.newIdSpec({ "userId" : "VIEWER" }); > req.add(req.newFetchPersonAppDataRequest(viewer, 'gifts', > opt_params), 'data'); > req.send(onLoadFriends); > > } > > function onLoadFriends(data) { > var viewer = data.get('viewer').getData(); > var viewerFriends = data.get('viewerFriends').getData(); > var giftData = data.get('data').getData(); > > html = new Array(); > html.push('<select id="person">'); > viewerFriends.each(function(person) { > if (person.getId()) { > html.push('<option value="', person.getId(), '">', > person.getDisplayName(), '</option>'); > } > }); > html.push('</select>'); > document.getElementById('friends').innerHTML = html.join(''); > updateGiftList(viewer, giftData, viewerFriends); > > } > > Kindly let me know the solution as soon as possible. > > Regards, > Parag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "OpenSocial Application Development" group. To post to this group, send email to opensocial-api@googlegroups.com To unsubscribe from this group, send email to opensocial-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/opensocial-api?hl=en -~----------~----~----~----~------~----~------~--~---