MySpace PHP API – 20 friend maximum return bug fix


While working with the MySpace official and unofficial php api libraries I became frustrated with one slight bug that was causing some pains for my application. I want to note first off that both of these libraries have been great tools to save from having to use the front end javascript api library that OpenSocial defines.

For our needs, we only needed 3 things from the library…the owner profile data, viewer profile data and the owner friend data. The problem here was that no matter what arguments I supplied to the built in functions I could never get back more than 20 friends, even though the standard specifies that it allows for a return of ‘all’ friends and that 20 was just a default. So, I started hacking away at the API and OAuth.php file of the unofficial library to see if I could find a solution.

What was the problem and how was it fixed?
What it looked like is that the OAuth request for friend profile data is temperamental when it comes to the order of the parameters being passed in the query string. It appears that the ‘page_size’ parameter has to be the first parameter passed after the request URI in order for the parameters to have any effect (i.e. http://api.myspace.com/v1/users/{USERID}/friends?page_size=40…). This parameter controls how many user profiles to send back through the request and can be set to ‘all’ for all of your friends’ profiles. So, I went into the OAuth.php file and switched the order that the OAuth and function parameter arrays were being merged. There was a slight issue in the friend request function in the unofficial php api (the array values were not passing correctly to the request function) so I adjusted those features and set up that argument array so that page_size would be the first element passed in to the request.

Where is the fix?
File: http://www.nakedtechnologist.com/files/ms_unofficial_php_api_with_friend_fix.zip

All you need to do is download the zip file, unzip it and replace the unofficial library files. The zip contains all of the files that were in the original API. To do a quick setup to display friend data, you can use the following PHP code:

<?php
require_once(’Space.php’);
$key = ‘http://www.myspace.com/xxxxx’;
$secret = ‘xxxxxxxxxxx’;
$session = new Space($key, $secret);
$friend_list = $session->friends(’USER_ID′,1,’all’);
var_dump($friend_list);
?>

I saw many questions on the forums regarding what the xxxxx portion of the $key parameter is. This is the friend id of your application, which may be viewed on the add application page (e.g. http://www.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=396659585).

– Jonathan LeBlanc

  • Share/Bookmark

2 Comments, Comment or Ping

  1. mshehabNo Gravatar

    Does the unofficial implementation work ? and is that patch working? Thank you..

    October 17th, 2009

  2. adminNo Gravatar

    The last time I checked it was working (but mind you this was about 8 months ago), and the patch should also work as well…but again that was the last time I checked ;)

    October 18th, 2009

Reply to “MySpace PHP API – 20 friend maximum return bug fix”

You must be logged in to post a comment.