I had a feeling when I wrote this that I'd end up writing the answer myself...
So this is my guide to making an application for people who aren't coders....
I am giving an example in PHP & using SMARTY TEMPLATING & FLASH.... but I am sure you could try other things.
THE VERY BASICS
- There are three surfaces:
- The profile surface, which appears on the user's profile.
- The home surface, which appears on the user's main MySpace login page (the page where they check their mail, etc).
- The canvas surface, which is where your main application will launch.
- There are two kinds of people you may be addressing
- The owner: "Hello Ownername, thank you for installing this application."
- The viewer: "Hello Viewername, Ownername has installed this application, why don't you?"
- It is actually very, very easy once you get the basics worked out.
GETTING STARTED
Most of you will have done this, if you're reading this - if not
OPEN A MYSPACE DEVELOPER ACCOUNT
Go to developer.myspace.com
Click on My Apps
Fill in the form.
Wait for approval.
If you don't have a developer account yet, you don't have to stop your development whilst you're waiting for approval!
Get designing your pages & get an idea of how your application is going to flow.
Then once you have a developer account it's time to start cracking....
ENTER THE BASICS OF YOUR APPLICATION
Like.. give it a name & stuff.
Don't worry about the Callback URLs and stuff.
MAKE A NOTE of your Application URI & Secret Keys though, because you are going to need them!
DOING THE CODE STUFF
SET UP YOUR SERVER TO USE THE RIGHT PHP STUFF
First things first. Get the official MySpace PHP Library.
http://x.myspace.com/libs/myspacel_php5_20080317.zip
Edit the file config.php to point to your Application URI and use your Secret Key (from the app info page)
Upload the contents of the myspace subdirectory to your PHP directory and also upload config.php to the same location.
Your PHP folder is probably located outside of your website root folder.
For example - mine is /usr/myusrname/php
But my website files are uploaded to /usr/myusrname/public_html
You'll also need to install the PEAR package, HTTP_Request.
If you are lucky, your website hosting provider may have set this up in CPANEL for you - go and check. It may be under Software/Services -> PHP Pear Packages. If so, just search for HTTP_Request and click install. If not, you'll need to download the package from PEAR.com - http://pear.php.net/ - and again upload to your PHP directory.
ENTER THE MYSPACE CODE THAT POINTS TO YOUR SERVER & RUNS THE APPLICATION
I got this chunk of code from
http://developer.myspace.com/Community/forums/p/402/1561.aspx#1561
& modified it slightly.
You can use it for all three views - you just need to change the width and height of the div in the style information to match. You enter this in the box under edit app source.
<style type="text/css">
//CHANGE THE WIDTH AND HEIGHT TO MATCH THE SURFACE YOU ARE USING THE CHUNK OF CODE FOR
.profile{
width: 800x;
height: 1600px;
//YOU CAN ADD IN ANY OTHER STYLE INFO YOU WANT HERE
}</style>
//THIS IS THE DIV THAT WILL BE REPLACED WITH YOUR APPLICATION - I PUT A LOADER IMAGE THERE.
<div id="output" class="profile"><img src="YOURLOADERIMAGE.GIF"></div>
<script type="text/javascript">
//THIS POINTS TO YOUR PHP SCRIPT
var server_url="http://YOURDOMAIN.com/YOURPHPSCRIPT.php";
function init() {
//THIS CODE GETS A BUNCH OF INFO FROM MYSPACE
var params = {};
params[opensocial.ContentRequestParameters.METHOD] = opensocial.ContentRequestParameters.MethodType.GET;
params[opensocial.ContentRequestParameters.CONTENT_TYPE] = opensocial.ContentRequestParameters.ContentType.HTML;
params[opensocial.ContentRequestParameters.AUTHENTICATION] = opensocial.ContentRequestParameters.AuthenticationType.SIGNED;
opensocial.Container.get().makeRequest(server_url, pageloadCallback, params);
}
//ONCE THAT INFO IS RECEIVED IT LOADS YOUR OWN PAGE INTO THE DIV WE MADE EARLIER
function pageloadCallback(response) {
document.getElementById('output').innerHTML = response;
}
//THIS LIL FUNCTION BELOW PROVIDES A LINK TO YOUR CANVAS PAGE FROM OTHER SURFACES
function gocanvas() {
var surfaces = gadgets.views.getSupportedViews();
var canvasSurface = surfaces['canvas'];
gadgets.views.requestNavigateTo(canvasSurface,null);
}
//THIS INITIALISES THE WHOLE THING OR SOMETHING
init();
</script>
MAKE YOUR "PHP CONTROL FILES"
I'm using Smarty - so my PHP control files just send a bunch of info to the templating system - I have three control files for each surface (home.php / profile.php and canvas.php) - when I get time I'll merge them into one and have it redirect according to a paramater or something.
If you're not using Smarty, it's still really easy to get what you need. Anyway, this is how my control file for my canvas looks.
<?php
//THIS BIT SETS UP MY SMARTY - YOU WILL NOT NEED THIS IF YOU ARE NOT USING SMARTY
require('/usr/myusrname/public_html/include/smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->compile_dir = '../compile';
//CHANGE THE BIT BELOW TO POINT TO THE ABSOLOOOOOOT LOCATION OF MYSPACEAPI
require_once('/usr/myusrname/php/myspace/MySpaceAPI.php');
$key = 'YOURKEY';
$secret = 'YOURSECRET';
$myspace = new MySpaceAPI($key,$secret);
//THIS GETS THE ID OF THE VIEWER
$user = $_GET["opensocial_viewer_id"];
//THIS TELL SMARTY TO ASSIGN THE STRING USERID TO WHATEVER THE ID OF THE VIEWER WAS
$smarty->assign('userid', $user);
//NOW WE GET SOME INFO - THIS CALLS THE FUNCTION GET USER FROM MYSPACE API & ASSIGNS THE RESULTS TO AN ARRAY CALLED RESULT
$result = $myspace->get_user($user);
//LOTS OF SMARTY ASSIGNS _ GET THE RIGHT PART OF THE ARRAY FROM RESULT & GIVE IT A SMARTY STRING
$smarty->assign('imageurl', $result['imageuri']);
$smarty->assign('profileurl', $result['weburi']);
$smarty->assign('name', $result['displayname']);
$smarty->assign('name', $result['displayname']);
$smarty->assign('usertype', $result['usertype']);
//AN EXAMPLE OF BREAKING UP AN ARRAY EVEN FURTHER
$myArray = $myspace->get_interests($user);
$music= $myArray['interests']['music'];
$bands = explode(',',$music);
$bandlist = array_rand($bands, 5);
$smarty->assign('bandlist', $bands[$bandlist[3]]);
//OK I GOT ALL THE INFO I NEED RENDER A PAGE PLZZZZZZZZZZZZ SOI SOI SOI SOI SOI
$smarty->display('canvas.tpl');
?>
AND FINALLY - FUN WITH SMARTY
So we just passed a ton of info into canvas.tpl :)
If you're using Smarty you can do stuff like:
{if $usertype == "Band"}
Hello - I see you are in a band called {$name} - are you any good?
{else}
Hello {$name} I see you are a fan of {$bandlist} well I think they suck.
{/if}
You can also pass this info into Flash using Flashvars...
<PARAM NAME=FlashVars VALUE="name={$name}&band={$bandlist}&usertype={$usertype}">
Then you can call the info into dynamic text fields using:
myTextField_txt.htmlText = "<font face='Arial' size='14' color='#FFFFFF'>thar thar, dun worry<b>"+name+"</b>its all gun b k</font>";
Oh yeah, remember that gocanvas() function earlier?
Well, you can use GetURL on a button in Flash on the homepage app & direct the user to the canvas page.
So that's it - my DUMMIES GUIDE TO APPS - for dummies like me. Hope it helps someone somewhere.