"RT @charlesLeahy1: Bloody migrants coming over here blocking our roads #amphibiancaravan"

@ashleyford 13 hours ago

"RT @RandyRainbow: This is the only news I care about today 🦃"

@ashleyford 4 days ago

Designer and web developer, Co-founder and Technical Director at Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]

MySpace Open Search API


The MySpace Search API allows you to search MySpace for user, videos, images, and music. With an individual feed for each search item. It is designed to function like a search on the MySpace website and to have a response format that is compatible with OpenSocial. The API returns either JSON or XML and in this tutorial i’ll be using PHP and CURL to parse an XML response to build a simple MySpace search page.

Application use

Open Search could be used to mash data using the MySpace API with other applications, for example automatically pulling in a users MySpace profile image, name, location and URL. Building a Facebook application that recommends bands to you on MySpace.

The Code

Just like the Twitter search API tutorial that I did a last year we’re using the CURL function in PHP5 to allow us to parse the XML file and format the data that we get back.

Here’s how it works

Any search that we make will send GET variables through the page URL therefore making it easy to see the data that we’re sending to the API generally you will see search pages use this method as we’re not transmitting private data such as usernames or passwords.

The search data is stored in the variable $q if nothing is searched for initially we run a default search mainly for demo purposes with the search term ‘Coldplay’. You’ll notice that the first result on the left is highlighted green, this is because it is the official profile for the Coldplay. you can see that we construct the URL and store it in the variable $search. There are many different variables that can be passed to the API. It’s worth pointing out that we’re using the People search call. You can see all the values that can be passed in here

Here is an example XML request:

//Search API Script



$q = 'coldplay';



$pics[0] = '&hasPhoto=on';
$pics[1] = 'checked';



$pics[0] = '&location='.urlencode($_GET['location']).'';


$search = "".urlencode($q)."&format=xml".$pics[0]."";

$cu = curl_init();

curl_setopt($cu, CURLOPT_URL, $search);
$result = curl_exec($cu);
$search_res = new SimpleXMLElement($result);

echo "<h3>".$search_res->totalResults." MySpace results for '".$q."'</h3>";

// Echo the Search Data

foreach ($search_res->entry as $user) {

$officialprofile = null;


$officialprofile = 'official';


echo "<div class='user ".$officialprofile."'><a href="".$user->profileUrl."" target="_blank"><img border="0" width="68" class="user_image" src="".$user->thumbnailUrl."" title="".$user->displayName."" /></a>";
echo "<div class='text'>".$user->displayName."</div> <strong>".$user->location."</strong><br/><a href='".$user->profileUrl."' >Visit ".$officialprofile." profile</a><div class='clear'></div></div>";



<div id="search">
<form action="" method="get">
  Search MySpace <input type="text" name="q" value="<?php echo $q;?>" id="searchbox" />
 Location <input type="text" name="location" value="<?php echo $_GET['location'];?>" id="location" />
  Only show users with profile pics <input name="pics" type="checkbox" value="1" <?php echo $pics[1];?> />
  <input type="submit" name="submit" id="submit" value="Search" />


Designer and web developer, Co-founder and Technical Director at Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]

Warning: count(): Parameter must be an array or an object that implements Countable in /nfs/c02/h08/mnt/40992/domains/ on line 399
Comments 3
  • Online Photography Classes
    Posted on

    Online Photography Classes Online Photography Classes

    Reply Author

    It is in reality a great and helpful piece of info. I am satisfied that you just shared this useful information with us. Please keep us informed like this. Thank you for sharing.

  • Nafun
    Posted on

    Nafun Nafun

    Reply Author

    Although it may be pretty quiet now, I would still like to integrate myspace on this page:

    Does the Myspace API allow posting via twitter?

  • Bakul Chandra Muni
    Posted on

    Bakul Chandra Muni Bakul Chandra Muni

    Reply Author

    It does not work.
    I get the error.

    Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ in /nfs/c02/h11/mnt/40992/domains/ Stack trace: #0 /nfs/c02/h11/mnt/40992/domains/ SimpleXMLElement->__construct(”) #1 {main} thrown in /nfs/c02/h11/mnt/40992/domains/ on line 110