MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Passing parameters and POST TO alternatives for external iframe based apps

Last post 04-27-2008 5:08 AM by Daniiiiiel™. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-25-2008 9:36 PM

    • CC
    • Top 200 Contributor
    • Joined on 02-08-2008
    • Posts 25

    Passing parameters and POST TO alternatives for external iframe based apps

    Many features are not available in external Iframe apps using REST api

    1. Passing variables/data over surface profile to canvas

    In Opensocial JS API the link from profile page that reads http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=xxxxxx&var1
    =hello

    can pass data to canvas surface by appending it (var1=hello) in canvas url

    The same thing for external iframe based app will not work
    External Iframe in canvas page reads like this
    <iframe id="apppanel_XXXXXX_canvas" src="http://externaldomain.com/app/?country=CA&lang=en&oauth_consumer_key=http%3
    A%2F%2Fwww.myspace.com%2FXXXXXXXX&oauth_nonce=xxxxxxxxxxxxxxxxxxxx
    &oauth_signature=xxxxxxxxxxxxxxxxxxx%3D&oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1209183007&oauth_token=&oauth_version=1.0
    &opensocial_owner_id=xxxxxxxxxx&opensocial_viewer_id=xxxxxxxx
    &pto=COMMENTS%2CBLOG%2CBULLETINS%2CPROFILE%2CSEND_MESSAGE"
    width="800" height="5000" scrolling="no" frameborder="0"
    style
    ="border: none; background:transparent;"></iframe>

    If any data appended in canvas url http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=xxxxxx
    &var1=hello&var2=xyz

    is reflected in src attribute of iframe like
    <iframe src="http://externaldomain.com/app/?country=CA..................&var1=hello
    &var2=xyz
    "></iframe>
    then external iframe based app can also pass data from profile to canvas surface

    2. POST TO feature
    Messaging feature is still not available in REST API.
    It will take time to get released. But till then if MDP team could implement this:

    URL for send message page reads like this
    http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=XXXXXXXXX
    Here also if we could append subject and body parameter in url so that it pre fills up the subject and message textbox there like

    http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=XXXXXXXXX
    &subject=check this app&body=my app link

    Similarly for comment and bulletin post like this

    http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm
    &friendID=278378076&body=my comment text

    http://bulletins.myspace.com/index.cfm?fuseaction=bulletin.edit&subject=bulletin subject
    &body=bulletin body text

    I guess it will not take much time to implement for MDP team. 

    You guys are doing great.

    Thanks

     

  • 04-26-2008 9:31 PM In reply to

    Re: Passing parameters and POST TO alternatives for external iframe based apps

    In Opensocial JS API the link from profile page that reads http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=xxxxxx&var1 =hello can pass data to canvas surface by appending it (var1=hello) in canvas url The same thing for external iframe based app will not work

    There is one parameter called "appParams" that's passed through to the canvas, as long as it's JSON encoded. Well, it's passed through if you're using HTML/JavaScript, I'd assume it'd be passed through for external iframes too. I needed to use the Canvas as a callback URL with GET parameters, so I've got a simple PHP script like this:

    <?php
    $appId = $_GET['appId'];
    unset($_GET['appId']);
    
    header('Location: http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=' . $appId . '&appParams=' . json_encode($_GET));
    ?>
    

    And you call this like http://stuff.daniel15.com/myspacedev/redirToCanvas.php?appId=xxxxxx&var1=hello&var2=xyz, which simply redirects to http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=xxxxxx&appParams={"var1":"hello","var2":"xyz"}. Alternatively, you could of course just JSON-encode your parameters in JavaScript.

    To access there parameters in your code, you'd use opensocial.getEnvironment().getParams()['var1'] in JavaScript, not sure if it's the same for iframe-based apps (I've never used them)

  • 04-27-2008 1:17 AM In reply to

    Re: Passing parameters and POST TO alternatives for external iframe based apps

    Yes, it does get passed through to External IFrames as well -- it's comes across the querystring in a parameter named 'p'.

    *ETA -- PS. Nice explanation on that Dan. :)

  • 04-27-2008 2:00 AM In reply to

    • CC
    • Top 200 Contributor
    • Joined on 02-08-2008
    • Posts 25

    Re: Passing parameters and POST TO alternatives for external iframe based apps

    Thanks Jeremy and Dan http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=xxxxxx
    &appParams=hello

    shows this in canvas page

    <iframe id="apppanel_xxxxx_canvas" src="http://xyz.com/?country=CA&lang=en
    &oauth_consumer_key=http%3A%2F%2Fwww.myspace.com%2F4545445454&oauth_nonce=4654654654
    &oauth_signature=dsadsadsadsadasddasd%3D&oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1209285941&oauth_token=&oauth_version=1.0&opensocial_owner_id=xxxxxxxxx
    &opensocial_viewer_id=xxxxxxxxx&p=hello&pto=COMMENTS%2CBLOG%2CBULLETINS%2CPROFILE%2CSEND_MESSAGE"
    width="800" height="5000" scrolling="no" frameborder="0" style="border: none; background:transparent;">
    </iframe

    But any ideas to pass more than one parameters in appParams?

    Also what about the message and comment box pre fill up thing? Thanks

  • 04-27-2008 5:08 AM In reply to

    Re: Passing parameters and POST TO alternatives for external iframe based apps

    But any ideas to pass more than one parameters in appParams?

    JSON encoding it is probably the best solution, because it's easy to encode/decode. Look at my previous post :)

    To encode something as JSON (really simple JavaScript example):

    <script type="text/javascript">
    var myObj = {
    	'var1': 'blah',
    	'var2': 'More blah'
    }
    
    var myObjJSON = gadgets.json.stringify(myObj);
    alert('JSON-encoded: ' + myObjJSON);
    </script>
    

    myObj is a JavaScript object, and myObjJSON would be the JSON representation of it.

    As for actually getting the data... Like I mentioned, you can use opensocial.getEnvironment().getParams()['var1'] on a regular HTML/CSS app. As for an iframe app, I guess you'd need to decode the "p" parameter manually. Most languages have JSON decoders (eg. json_decode() in PHP 5)

    Also what about the message and comment box pre fill up thing? Thanks

    Something like PostTo?
    http://www.myspace.com/posttomyspace
    Looks like it's been disabled for now, though. Additionally, the current version only supports text in the about me, blog posts, and bulletins.

Page 1 of 1 (5 items)