MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Problem Multiple Invites

Last post 07-07-2009 9:30 AM by Steve. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 07-02-2009 7:15 PM

    Problem Multiple Invites

    I'm Trying to implement the new multiple Invites into my application ... I am trying allow users to invite the first ten friends to my app... ITS NOT WORKING -this is what I have so far... I think it should work but it doesnt

     

     

    <div id='heading'></div>
    <hr size="1px" />
    <script type="text/javascript">
    var os;
    var dataRequest;
    function dataRequest()
    {
        os = opensocial.Container.get();
        dataRequest = os.newDataRequest();
        var friendsParams = {
        }
        ;
        friendsParams[ opensocial.DataRequest.PeopleRequestFields.FILTER ] = opensocial.DataRequest.FilterType.ALL;
        friendsParams[ opensocial.DataRequest.PeopleRequestFields.FIRST] = 0;
        friendsParams[ opensocial.DataRequest.PeopleRequestFields.MAX ] = 10;
        friendsParams[ MyOpenSpace.DetailType.GET_ONLINE ] = true;
        friendsParams[ MyOpenSpace.DetailType.GET_STATUS ] = true;
        friendsParams[ MyOpenSpace.DetailType.GET_MOOD ] = true;
        var FRIENDSReq = os.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, friendsParams);
        dataRequest.add(FRIENDSReq);
        dataRequest.send(getResponse);
    }
    function getResponse(response)
    {
        if( response.hadError() )
        {
            document.write("There is an error in the response. <br>");
            return;
        }
    var recipients;
    recipients = [;
        var VIEWER_FRIENDS = response.get(opensocial.DataRequest.Group.VIEWER_FRIENDS).getData().asArray();
        for(var i=0; i < VIEWER_FRIENDS.length; i++)
        {

    recipients.push(VIEWER_FRIENDSIdea.getField(opensocial.Person.Field.ID))
    document.write(VIEWER_FRIENDSIdea.getField(opensocial.Person.Field.ID)+" "+recipients+"<br>");

        }

    document.write('<input type ="button" onclick="multipleRSAWrapper();" value="jjjg">');
    }
    function multipleRSAWrapper(){
        // create the rSA message
        var body = "Hey [recipient]! [sender] wants you to ";
        body += "add [app]. It's way awesome!";
     
        // create an opensocial.Message object
        var reason = opensocial.newMessage(body);
     
        // initiate requestShareApp
        opensocial.requestShareApp(recipients, reason, function(){ alert('done'); });
    }
    dataRequest();
    </script>

  • 07-03-2009 6:23 AM In reply to

    Re: Problem Multiple Invites

     any help???

  • 07-05-2009 8:05 PM In reply to

    Re: Problem Multiple Invites

     ??? HELP

  • 07-05-2009 10:42 PM In reply to

    Re: Problem Multiple Invites

     There are some script errors in this code that need to be fixed first.  You have to close the array being declared as "recipients".  Also, what you're doing with declaring dataRequest as a variable, redefining it as a function, then internally reassigning it to an instance of a DataRequest is going to cause you trouble. It's legal code, but is a bear to maintain and debug.  Additionally, the object MyOpenSpace.DetailType is coming up undefined when I step the code, which is causing an exception to be thrown prior to performing the request.  I'd also encourage you to initialize the recipient list by registering the dataRequest initializer function with gadgets.util.registerOnLoadHandler instead of making a direct inline call.  Additionally, the ID you're using to get the friends does not work with 0.8.  The call to create the newFetchPeopleRequest is failing because opensocial.DataRequest.Group.VIEWER_FRIENDS is not defined.  You need to use the idSpec object instead.  You are also using an anonymous data request.  You're much better off specifying a key so you can more easily retrieve the data.

     Once I got through the main errors that were throwing exceptions, I found your paging to be wrong.  Paging must start from 1, not zero.  Once all that was fixed, the scope on your recipients array was wrong.  It was declared in the callback handler, so was undefined when the rsaWrapper function called.  You need to scope it to the window object

    The full OpenSocial Javascript docs may be found at opensocial.org.

    http://wiki.opensocial.org/index.php?title=JavaScript_API_Reference

    I would encourage you to use Firefox 3.5 with the latest Firebug, or to use IE8 with the built-in script debugger to trace these kinds of issues.  Inserting a debugger; statement in the code will trigger the debugger to launch and break.  Most of your frustration is probably coming from using objects from the wrong OpenSocial version.  Also, don't use document.write.  It has horrible performance and clears your page contents, which I don't think is what you want.  Use the DOM api instead.

     

    Soooooo.  Since I took the time to trace all this, here is the updated source code.  This is 0.8 compliant (you should no longer be using 0.7 anyway). Some of the examples on the site are from 0.7, so this is another gotcha.

    ---------------

    <Multiple Invites>
    <script type='text/javascript'>
    //debugger;
    var os;
    var friendDataRequest;
    function initDataRequest()
    {
    //debugger;
    os = opensocial.Container.get();
    friendDataRequest= os.newDataRequest();
    var friendsParams = {
    }
    ;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.FILTER ] = opensocial.DataRequest.FilterType.ALL;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.FIRST] = 1;
    friendsParams[ opensocial.DataRequest.PeopleRequestFields.MAX ] = 10;
    /*
    friendsParams[ MyOpenSpace.DetailType.GET_ONLINE ] = true;
    friendsParams[ MyOpenSpace.DetailType.GET_STATUS ] = true;
    friendsParams[ MyOpenSpace.DetailType.GET_MOOD ] = true;
    */
    var idparams = {};
    idparams[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
    idparams[opensocial.IdSpec.Field.GROUP_ID] = opensocial.IdSpec.GroupId.FRIENDS;
    var id = opensocial.newIdSpec(idparams);

    var FRIENDSReq = os.newFetchPeopleRequest(id, friendsParams);
    friendDataRequest.add(FRIENDSReq, "friends");
    friendDataRequest.send(getResponse);
    }

    var recipients = [;

    function getResponse(response)
    {
    //debugger;
    if( response.hadError() )
    {
    writeMessage(response.getErrorMessage());
    return;
    }
    var VIEWER_FRIENDS = response.get("friends").getData().asArray();
    for(var i=0; i gt;");

    }

    }
    function multipleRSAWrapper(){
    //debugger;
    // create the rSA message
    var body = "Hey [recipient]! [sender] wants you to ";
    body += "add [app]. It's way awesome!";

    // create an opensocial.Message object
    var reason = opensocial.newMessage(body);

    // initiate requestShareApp
    opensocial.requestShareApp(recipients, reason, function(){ writeMessage('gt; SENT INVITES'); });
    }

    function writeMessage(msg){
    var elem = document.getElementById('msg');
    if(elem){
    elem.innerHTML += msg
    }

    }

    gadgets.util.registerOnLoadHandler(initDataRequest);
    </script>
    <button  onclick="multipleRSAWrapper();" >Multi Invite</button>

    <div id="msg"> </div>

     

     

     

     

  • 07-05-2009 11:08 PM In reply to

    Re: Problem Multiple Invites

     Thanks for the BIG help ... i'm glad you took the time =] 

     

     

    ... I tested it and it did not work

  • 07-06-2009 3:48 PM In reply to

    Re: Problem Multiple Invites

     Make sure your app is set to 0.8 and not 0.7.  Then get set up with firebug and trace where it's failing.  The code might have gotten mangled when it was pasted into the forums.  Also, you need to visit your app'sProfile page and manually install for some of the functionality to work.  It can't always find your friends if the app isn't installed.

  • 07-06-2009 3:57 PM In reply to

    Re: Problem Multiple Invites

     I noticed nothing is happening with the recipients... Can you help?? ALSO - If an error is in javascript willl that cause all functions within the tags to not execute ?

  • 07-07-2009 9:30 AM In reply to

    Re: Problem Multiple Invites

       I did both ... I'm not used to firebug... I tried it but I dont really know how to use it.

Page 1 of 1 (8 items)