Welcome Developers!

in

Welcome!

in

opensocial is not defined

Last post 01-04-2010 3:18 PM by Chad Russell. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-08-2009 8:09 AM

    • dan
    • Not Ranked
    • Joined on 02-24-2009
    • Posts 5

    opensocial is not defined

     So I'm trying to write my first app, but keep stumbling at the first step. I've followed the example (http://wiki.developer.myspace.com/index.php?title=Example_Application:_Hello_World),and pasted this exact code into my profile surface.

    <div id='heading'></div>
    <hr size="1px" />
     
    <script type="text/javascript">
     
    var os;
    var dataReqObj;
    var heading = null;
     
    function init() {
        os = opensocial.Container.get();
        dataReqObj = os.newDataRequest();
        var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER);
        dataReqObj.add(viewerReq);
        dataReqObj.send(viewerResponse);
    }
    function viewerResponse(data) {
        var viewer = data.get(opensocial.DataRequest.PersonId.VIEWER).getData();
        heading = 'Hello, ' + viewer.getDisplayName();
        document.getElementById('heading').innerHTML = heading;
    }
    init();
    </script>

    However, as soon as I run it, there's a JS error saying, "opensocial is not defined". So the app fails. I keep getting the same with "gadgets" too.I can see in the <head> that the javascript is all included, but it's still not working.

    Now I'm a pretty experienced coder, and wonder whatuber-simple mistakeI'm making?!! Arrrgh, it's so frustraiting!

  • 05-11-2009 7:54 AM In reply to

    Re: opensocial is not defined

     Interesting, but I'm not even getting that. I'll send this in. I've also tested on .7 and .8

    Will get back with you. :)

    Rhonda

     

  • 05-11-2009 8:13 AM In reply to

    • Casidy
    • Not Ranked
    • Joined on 05-01-2009
    • Posts 6

    Re: opensocial is not defined

    I ran into the same problem. Here's what I got to work using opensocial .8

    var os; var dataReqObj; var heading = null; function init() { os = opensocial.Container.get(); dataReqObj = os.newDataRequest(); var viewerReq = os.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER); dataReqObj.add(viewerReq, 'viewer'); dataReqObj.send(viewerResponse); } function viewerResponse(data) { var viewer = data.get("viewer").getData(); heading = 'Hello', + viewer.getDisplayName(); document.getElementById('heading').innerHTML = heading; } init();
  • 05-12-2009 1:03 PM In reply to

    Re: opensocial is not defined

     Hi, I tried copying/pasting the code you quoted into an app and it seemed to work correctly for me, in both canvas and profile surfaces.  That code is rather old and OpenSocial version 0.7 specific.  So make sure the app is set to 0.7 or it'll fail (0.8 is the default).  Go to the Edit App Information tab for the app, scroll down to Preferred OpenSocial Version, and make sure 0.7 is selected.

    It may actually be better to try and run it in 0.8, changing both instances of:

     opensocial.DataRequest.PersonId.VIEWER

    to:

     opensocial.IdSpec.PersonId.VIEWER

    Is probably all it'll take, but I haven't tried it to confirm.

    Thanks,

    Chad

  • 09-30-2009 7:14 AM In reply to

    Re: opensocial is not defined

    Hi!

    I'm getting this error inmy iframe app:

    opensocial is not defined

    http://wiki.developer.myspace.com/index.php?title=Messaging_from_an_IFrame
    and here
    http://developer.myspace.com/Community/blogs/devteam/archive/2009/07/31/fix-for-appinvites-and-iframe-app.aspx
     
    iframe resize works fine.
     
    Please, help me to solve this!

     

  • 11-05-2009 3:34 AM In reply to

    • Snapps
    • Not Ranked
    • Joined on 10-13-2009
    • Posts 8

    Re: opensocial is not defined

     Hi, even iam getting the same error, opensocial is not defined.

    Please anyone clarify this. Iam using an iframe and i configured my app with 0.7 version.

    Dont know what to do, please anyone help me. Sad

  • 11-16-2009 4:43 PM In reply to

    Re: opensocial is not defined

    Hey, check the app found here for details instructions on how to enable messaging from an external iframe app:

    http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=124833

    Note that you can only enable messaging features, like app invites, using this, you can't access any data (friend lists, etc).  To access data you'll need to use the various SDKs to hit the REST APIs.

    Chad

  • 12-18-2009 5:46 AM In reply to

    • Adrian
    • Not Ranked
    • Joined on 06-25-2009
    • Posts 5

    Re: opensocial is not defined

     Hi,

    I am experiencing this issue too and cannot resolve it.

    My app already uses messaging (from examples) and javascript code such as:

     

    script type="text/javascript"

    var container = MyOpenSpace.MySpaceContainer.get();
    container.adjustHeight(); //This will try to fit the enclosing content.


    /script

     

    At the top of my page i declaire the following:

    <script src="http://x.myspacecdn.com/OpenSocial/references/gadgets003.js" type="text/javascript"></script>
    <script src="http://x.myspacecdn.com/modules/common/static/js/Apps/ifpc003.js" type="text/javascript"></script>
    <script src="http://x.myspacecdn.com/modules/common/static/js/Apps/json001.js" type="text/javascript"></script>
    <script src="http://x.myspacecdn.com/OpenSocial/IFPC_externalIframe004.js" type="text/javascript"></script>

    <script type="text/javascript" src="http://js.myspacecdn.com/OpenSocial/RPC/RpcContainer.003.js"></script>
    <script type="text/javascript" src="IFPC_externalIframe006.js" ></script>

    <script type="text/javascript">
    gadgets.rpc.setRelayUrl('..', 'http://profile.myspace.com/Modules/Applications/Pages/rpc_relay.aspx');
    </script>

     

    All i want to do is retrieve the users name but all example code at best is giving me the error : 'opensocial is not defined'

    this normally occurs on a line such as: ' os = opensocial.Container.get(); '

     

    My app is an external iframe app using multiple aspx pages (code does not execute on main page so its not to do with passing parameters through although this is already done too)

     

    Any help would be great as this would improve interaction between myspace api and an already active app. 

    Thanks

  • 01-04-2010 3:18 PM In reply to

    Re: opensocial is not defined

     Hi, in order to fetch data in an external iframe app you need to hit the REST API directly via one of our SDKs: http://wiki.opensocial.org/index.php?title=Client_Libraries

    Thanks,

    Chad

Page 1 of 1 (9 items)