MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Implementation of opensocial.requestShareApp in the AS3 library?

Last post 01-18-2009 6:16 PM by minekazz. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-28-2008 9:10 AM

    • kalle
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 5

    Implementation of opensocial.requestShareApp in the AS3 library?

     Hi!

     

    apparantly the following code works in JS:

               
                var message = opensocial.newMessage(someText);
               
                    opensocial.requestShareApp(someUserId, message,
                        function(){
                            alert('sent application invite');
                        }
                    );

     

    since it's a new feature, it's not included in the official AS3 library. Can anyone post a AS solution that does not include ExternalInterface?

     

    The JS code looks like this (can be found in http://api.msappspace.com/OpenSocial/MyOpenSpace020.Core.v07.js )

    MyOpenSpace.MySpaceContainer.prototype.requestShareApp = function(recipients, reason, opt_callback){

    if(!isNaN(parseInt(recipients, 10)) && recipients.constructor !== Array){
    var request = opensocial.newDataRequest();
    request.add(request.newFetchPeopleRequest(recipients));
    reason.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.SHARE_APP);
    request.message = reason;
    request.opt_callback = opt_callback;
    request.send(opensocial.Container.get().requestSendMessageWrapper);
    }
    else{
    return {"errorCode":opensocial.ResponseItem.Error.BAD_REQUEST,"errorMessage":"Unsupported idSpec, only one friend ID is allowed."};
    }


    }

    MyOpenSpace.MySpaceContainer.prototype.requestSendMessage = function(recipients, message, opt_callback){
    var type = message.getField(opensocial.Message.Field.TYPE);
    if(type === opensocial.Message.Type.NOTIFICATION || type === opensocial.Message.Type.PRIVATE_MESSAGE || type === opensocial.Message.Type.PUBLIC_MESSAGE){
    if(recipients === opensocial.DataRequest.PersonId.OWNER || recipients === opensocial.DataRequest.PersonId.VIEWER){
    var request = opensocial.newDataRequest();
    request.add(request.newFetchPersonRequest(recipients));
    request.message = message;
    request.opt_callback = opt_callback;
    request.send(opensocial.Container.get().requestSendMessageWrapper);
    }
    else if(!isNaN(parseInt(recipients, 10)) && recipients.constructor !== Array){
    var request = opensocial.newDataRequest();
    request.add(request.newFetchPeopleRequest(recipients));
    request.message = message;
    request.opt_callback = opt_callback;
    request.send(opensocial.Container.get().requestSendMessageWrapper);
    }
    else{
    return {"errorCode":opensocial.ResponseItem.Error.BAD_REQUEST,"errorMessage":"Unsupported idSpec, only VIEWER, OWNER or one friend ID is allowed."};
    }
    }
    else{
    return {"errorCode":opensocial.ResponseItem.Error.BAD_REQUEST,"errorMessage":"Unsupported message type. Only opensocial.Message.Type.(NOTIFICATION || PUBLIC_MESSAGE || PRIVATE_MESSAGE) are allowed."};
    }
    };

    MyOpenSpace.MySpaceContainer.prototype.requestSendMessageWrapper = function(response){
    if(!response.hadError()){
    var id = null;
    if(response.get(opensocial.DataRequest.PersonId.OWNER)) id = opensocial.DataRequest.PersonId.OWNER;
    else if(response.get(opensocial.DataRequest.PersonId.VIEWER)) id = opensocial.DataRequest.PersonId.VIEWER;
    else{
    for(var key in response.responseItems_){
    if(0 === key.indexOf("PERSON_") || 0 === key.indexOf("PERSON_")){
    id = key;
    break;
    }
    }
    }

    if(null !== id){
    var person;
    if(id === opensocial.DataRequest.PersonId.OWNER || id === opensocial.DataRequest.PersonId.VIEWER)
    person = response.get(id).getData();
    else
    person = response.get(id).getData().asArray()[0];
    var message = response.get(id).getOriginalDataRequest().message;
    var opt_callback = response.get(id).getOriginalDataRequest().opt_callback;

    opensocial.Container.get().postTo("", message, person, opt_callback);
    }
    }
    };

     

     

     

  • 08-28-2008 9:12 AM In reply to

    • kalle
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 5

    Re: Implementation of opensocial.requestShareApp in the AS3 library?

    OR, if someone can solve sendMessage or even both, it would be even better.

  • 01-18-2009 6:16 PM In reply to

    Re: Implementation of opensocial.requestShareApp in the AS3 library?

    I cant get it works too.

Page 1 of 1 (3 items)